/*
 * Copyright (C) 2016 yixun All Rights Reserved.
 * 
 * ProjectInfoService.java
 */
package com.emm.yixun.estate.service.impl.app;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.jws.WebService;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.emm.yixun.basic.enums.ModelEnum;
import com.emm.yixun.basic.mapper.PriceSchemeDetailMapper;
import com.emm.yixun.basic.mapper.PriceSchemeMapper;
import com.emm.yixun.basic.mapper.ProjectMapper;
import com.emm.yixun.basic.mapper.ProjectRoomMapper;
import com.emm.yixun.basic.service.AreaService;
import com.emm.yixun.basic.service.DataPermissionService;
import com.emm.yixun.basic.service.ModelKeyService;
import com.emm.yixun.basic.service.PmoLogService;
import com.emm.yixun.basic.service.PriceSchemeDetailService;
import com.emm.yixun.basic.service.ProjectBuildingService;
import com.emm.yixun.basic.service.ProjectHouseTypeService;
import com.emm.yixun.basic.service.ProjectImgService;
import com.emm.yixun.basic.service.ProjectInfoService;
import com.emm.yixun.basic.service.ProjectPmoService;
import com.emm.yixun.basic.service.ProjectPremisesInfoService;
import com.emm.yixun.basic.service.ProjectPremisesPmoService;
import com.emm.yixun.basic.service.ProjectPremisesService;
import com.emm.yixun.basic.service.ProjectRoomService;
import com.emm.yixun.basic.service.ProjectService;
import com.emm.yixun.basic.service.ProjectUnitService;
import com.emm.yixun.basic.service.SaleReturnPmoService;
import com.emm.yixun.basic.service.SalesTargetPmoService;
import com.emm.yixun.basic.service.SignedService;
import com.emm.yixun.basic.service.SubscribeService;
import com.emm.yixun.basic.service.UserService;
import com.emm.yixun.common.app.AddProjectRealMapReqDto;
import com.emm.yixun.common.app.AddProjectRealMapResDto;
import com.emm.yixun.common.app.DelProjectRealMapReqDto;
import com.emm.yixun.common.app.DelProjectRealMapResDto;
import com.emm.yixun.common.app.GetBuildingListReqDto;
import com.emm.yixun.common.app.GetBuildingListResDto;
import com.emm.yixun.common.app.GetDealHouseListReqDto;
import com.emm.yixun.common.app.GetDealHouseListResDto;
import com.emm.yixun.common.app.GetDealHouseTypeListReqDto;
import com.emm.yixun.common.app.GetDealHouseTypeListResDto;
import com.emm.yixun.common.app.GetHouseTypeListReqDto;
import com.emm.yixun.common.app.GetHouseTypeListResDto;
import com.emm.yixun.common.app.GetHousesDetailReqDto;
import com.emm.yixun.common.app.GetHousesDetailResDto;
import com.emm.yixun.common.app.GetHousesListReqDto;
import com.emm.yixun.common.app.GetHousesListResDto;
import com.emm.yixun.common.app.GetMarketingControlListReqDto;
import com.emm.yixun.common.app.GetMarketingControlListResDto;
import com.emm.yixun.common.app.GetPaymentNotSignedListReqDto;
import com.emm.yixun.common.app.GetPaymentNotSignedListResDto;
import com.emm.yixun.common.app.GetPremisesListReqDto;
import com.emm.yixun.common.app.GetPremisesListResDto;
import com.emm.yixun.common.app.GetPriceRecordListReqDto;
import com.emm.yixun.common.app.GetPriceRecordListResDto;
import com.emm.yixun.common.app.GetProjectListReqDto;
import com.emm.yixun.common.app.GetProjectListResDto;
import com.emm.yixun.common.app.GetRoomListReqDto;
import com.emm.yixun.common.app.GetRoomListResDto;
import com.emm.yixun.common.app.GetSalesTargetListReqDto;
import com.emm.yixun.common.app.GetSalesTargetListResDto;
import com.emm.yixun.common.app.GetStockHouseListReqDto;
import com.emm.yixun.common.app.GetStockHouseListResDto;
import com.emm.yixun.common.app.GetStockTimeListReqDto;
import com.emm.yixun.common.app.GetStockTimeListResDto;
import com.emm.yixun.common.app.GetTimeConditionAnalysisReqDto;
import com.emm.yixun.common.app.GetTimeConditionAnalysisResDto;
import com.emm.yixun.common.app.GetUnitListReqDto;
import com.emm.yixun.common.app.GetUnitListResDto;
import com.emm.yixun.common.app.ProjectsPmoReqDto;
import com.emm.yixun.common.app.ProjectsPmoResDto;
import com.emm.yixun.common.app.servletentity.BuildingListRes;
import com.emm.yixun.common.app.servletentity.BuildingStatusListRes;
import com.emm.yixun.common.app.servletentity.DealHouseTypeListRes;
import com.emm.yixun.common.app.servletentity.FlatMapListRes;
import com.emm.yixun.common.app.servletentity.FloorListRes;
import com.emm.yixun.common.app.servletentity.GetDealHouseListRes;
import com.emm.yixun.common.app.servletentity.GetPaymentNotSignedListRes;
import com.emm.yixun.common.app.servletentity.GetStockTimeListRes;
import com.emm.yixun.common.app.servletentity.HouseTypeListRes;
import com.emm.yixun.common.app.servletentity.PremisesListRes;
import com.emm.yixun.common.app.servletentity.ProjectList;
import com.emm.yixun.common.app.servletentity.PropertyTypeListRes;
import com.emm.yixun.common.app.servletentity.RealMapListRes;
import com.emm.yixun.common.app.servletentity.RoomListRes;
import com.emm.yixun.common.app.servletentity.SalesTargetListRes;
import com.emm.yixun.common.app.servletentity.UnitListRes;
import com.emm.yixun.common.enums.ResultEnum;
import com.emm.yixun.common.exception.XFUNExceptionCode;
import com.emm.yixun.common.model.Area;
import com.emm.yixun.common.model.PriceScheme;
import com.emm.yixun.common.model.PriceSchemeDetail;
import com.emm.yixun.common.model.Project;
import com.emm.yixun.common.model.ProjectBuilding;
import com.emm.yixun.common.model.ProjectHouseType;
import com.emm.yixun.common.model.ProjectImg;
import com.emm.yixun.common.model.ProjectInfo;
import com.emm.yixun.common.model.ProjectPmo;
import com.emm.yixun.common.model.ProjectPremises;
import com.emm.yixun.common.model.ProjectPremisesInfo;
import com.emm.yixun.common.model.ProjectPremisesPmo;
import com.emm.yixun.common.model.ProjectRoom;
import com.emm.yixun.common.model.ProjectUnit;
import com.emm.yixun.common.model.SaleReturnPmo;
import com.emm.yixun.common.model.SalesTargetPmo;
import com.emm.yixun.common.model.User;
import com.emm.yixun.common.model.appDto.CustomerCountDto;
import com.emm.yixun.common.model.appDto.DealHouseCount;
import com.emm.yixun.common.model.appDto.PriceRecordCount;
import com.emm.yixun.common.model.appDto.ProjectRoomCount;
import com.emm.yixun.common.model.appDto.ProjectRoomFloorList;
import com.emm.yixun.common.model.appDto.SalesTargetCount;
import com.emm.yixun.common.model.appDto.TimeConditionAnalysisReq;
import com.emm.yixun.common.model.appDto.TimeConditionAnalysisResAmount;
import com.emm.yixun.common.model.dto.AreaDto;
import com.emm.yixun.common.model.dto.PmoLogDto;
import com.emm.yixun.common.model.dto.ProjectBuildingDto;
import com.emm.yixun.common.model.dto.ProjectDto;
import com.emm.yixun.common.model.dto.ProjectImgDto;
import com.emm.yixun.common.model.dto.ProjectInfoDto;
import com.emm.yixun.common.model.dto.ProjectPmoDto;
import com.emm.yixun.common.model.dto.ProjectPremisesDto;
import com.emm.yixun.common.model.dto.ProjectPremisesInfoDto;
import com.emm.yixun.common.model.dto.ProjectPremisesPmoDto;
import com.emm.yixun.common.model.dto.ProjectRoomDto;
import com.emm.yixun.common.model.dto.ProjectUnitDto;
import com.emm.yixun.common.model.dto.SaleReturnPmoDto;
import com.emm.yixun.common.model.dto.SalesTargetPmoDto;
import com.emm.yixun.common.model.dto.SignedDto;
import com.emm.yixun.common.model.dto.SubscribeDto;
import com.emm.yixun.common.model.dto.UserDto;
import com.emm.yixun.common.model.enums.DelFlagEnum;
import com.emm.yixun.common.model.enums.ObjectTypeEnum;
import com.emm.yixun.common.model.enums.PaymentMethodEnum;
import com.emm.yixun.common.model.enums.ProjectTypeEnum;
import com.emm.yixun.common.model.enums.PropertyTypeEnum;
import com.emm.yixun.common.model.enums.RoomStatusEnum;
import com.emm.yixun.common.model.enums.SaleReturnEnum;
import com.emm.yixun.common.model.pmo.CityInfo;
import com.emm.yixun.common.model.pmo.PlanneBack;
import com.emm.yixun.common.model.pmo.PlannedSales;
import com.emm.yixun.common.utils.FileUploadPorxyUtil;
import com.emm.yixun.common.utils.SequencesGenerator;
import com.emm.yixun.estate.service.app.ProjectInfoServiceAppFacade;
import com.emm.yixun.estate.service.impl.app.manage.GetBuildingListManage;
import com.emm.yixun.estate.service.impl.app.manage.GetHouseTypeListManage;
import com.emm.yixun.estate.service.impl.app.manage.GetPremisesListManage;
import com.emm.yixun.estate.service.impl.app.manage.GetRoomListManage;
import com.emm.yixun.estate.service.impl.app.manage.GetUnitListManage;

/**
 * [文件名称]<br>
 * ProjectInfoServiceAppFacadeImpl.java<br>
 * <br>
 * [文件描述]<br>
 * 房产项目信息 service interface<br>
 */
@Service("projectInfoServiceAppFacade")
@WebService(endpointInterface="com.emm.yixun.estate.service.app.ProjectInfoServiceAppFacade")
public class ProjectInfoServiceAppFacadeImpl implements ProjectInfoServiceAppFacade{

	private final Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	private ProjectService projectService;
	@Autowired
	private GetHouseTypeListManage getHouseTypeListManage;
	@Autowired
	private GetPremisesListManage getPremisesListManage;
	@Autowired
	private GetBuildingListManage getBuildingListManage;
	@Autowired
	private GetUnitListManage getUnitListManage;
	@Autowired
	private GetRoomListManage getRoomListManage;
	@Autowired
	private ProjectMapper projectMapper;
	@Autowired
	private ProjectImgService projectImgService;
	@Autowired
	private ProjectPremisesService projectPremisesService;
	@Autowired
	private ProjectRoomMapper projectRoomMapper;
	@Autowired
	private ProjectBuildingService projectBuildingService;
	@Autowired
	private ProjectUnitService projectUnitService;
	@Autowired
	private ProjectRoomService projectRoomService;
	@Autowired
	private PriceSchemeDetailService priceSchemeDetailService;
	@Autowired
	private PriceSchemeMapper priceSchemeMapper;
	@Autowired
	private PriceSchemeDetailMapper priceSchemeDetailMapper;
	@Autowired
	private ProjectHouseTypeService projectHouseTypeService;
	@Autowired
	private UserService userService;
	@Autowired
	private DataPermissionService dataPermissionService;
	@Autowired
	private SalesTargetPmoService salesTargetPmoService;
	@Autowired
	private ProjectPmoService projectPmoService;
	@Autowired
	private AreaService areaService;
	@Autowired
	private ProjectInfoService projectInfoService;
	@Autowired
	private ProjectPremisesPmoService projectPremisesPmoService;
	@Autowired
	private ProjectPremisesInfoService projectPremisesInfoService;
	@Autowired
	private ModelKeyService modelKeyService;
	@Autowired
	private PmoLogService pmoLogService;
	@Autowired
	private SaleReturnPmoService saleReturnPmoService;
	@Autowired
	private SignedService signedService;
	@Autowired
	private SubscribeService subscribeService;
	
	@Value("${file.serviceUrl}")
	private String fileUploadUrl;
	
	DecimalFormat df = new DecimalFormat("#.00");
	
	/**
     * getProjectList:(app查询项目列表接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetProjectListResDto getProjectList(GetProjectListReqDto reqDto){
		GetProjectListResDto resDto = new GetProjectListResDto();
		try{
			//项目数据权限校验
			String dataPermission = dataPermissionService.dataPermissionCondition(Long.valueOf(reqDto.getUserId()), "menu_0003_0001", "t", null);
			String [] str_permission = dataPermission.split(":");
			if("00".equals(str_permission[0])){
				resDto.setErrorCode(XFUNExceptionCode.USER_PRODUCTNOEXIST.getCode());
				resDto.setErrorMsg(XFUNExceptionCode.USER_PRODUCTNOEXIST.getDesin());
				resDto.setResult(ResultEnum.FAILURE.getNo());
				return resDto;
			}
			
			//根据商户Id查询出所有项目集合list
			ProjectDto proDto = new ProjectDto();
			proDto.setMerchantId(Long.valueOf(reqDto.getMerchantId()));
			proDto.setDataPermission(str_permission[1]);
			List<Project> project = projectService.selectListByDto(proDto);
			List<ProjectList> projectList = new ArrayList<ProjectList>();
			if(project.size() > 0){
				for(int i=0;i<project.size();i++){
					ProjectList pro = new ProjectList();
					pro.setProjectId(String.valueOf(project.get(i).getId()));//项目Id
					pro.setProjectCode(project.get(i).getProjectCode());//项目编码
					pro.setProjectName(project.get(i).getProjectName());//项目名称
					projectList.add(pro);
				}
				resDto.setProjectList(projectList);
			}else{
				resDto.setProjectList(null);
			}
		}catch(Exception e){
			e.printStackTrace();
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}
	
	@Override
	public GetHouseTypeListResDto getHouseTypeList(GetHouseTypeListReqDto reqDto) {
		//1、版本校验(待定)
		//2、客户验签(待定)
		//3、获取当前登录用户
		//4、查询可关注户型
		return getHouseTypeListManage.getHouseTypeList(reqDto);
	}

	@Override
	public GetPremisesListResDto getPremisesList(GetPremisesListReqDto reqDto) {
		//1、版本校验(待定)
		//2、客户验签(待定)
		//3、获取当前登录用户
		//4、查询可关注组团(楼盘)
		return getPremisesListManage.getPremisesList(reqDto);
	}

	@Override
	public GetBuildingListResDto getBuildingList(GetBuildingListReqDto reqDto) {
		//1、版本校验(待定)
		//2、客户验签(待定)
		//3、获取当前登录用户
		//4、查询可关注组团(楼盘)
		return getBuildingListManage.getBuildingList(reqDto);
	}

	@Override
	public GetUnitListResDto getUnitList(GetUnitListReqDto reqDto) {
		//1、版本校验(待定)
		//2、客户验签(待定)
		//3、获取当前登录用户
		//4、查询可关注组团(楼盘)
		return getUnitListManage.getUnitList(reqDto);
	}

	@Override
	public GetRoomListResDto getRoomList(GetRoomListReqDto reqDto) {
		//1、版本校验(待定)
		//2、客户验签(待定)
		//3、获取当前登录用户
		//4、查询可关注组团(楼盘)
		return getRoomListManage.getRoomList(reqDto);
	}

	/**
     * getHousesList:(app查询房源列表接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param product 项目Id
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetHousesListResDto getHousesList(GetHousesListReqDto reqDto) {
		GetHousesListResDto resDto = new GetHousesListResDto();
		try{
			List<FlatMapListRes> flatMapList = new ArrayList<FlatMapListRes>();//总平图列表
			List<PremisesListRes> premisesList = new ArrayList<PremisesListRes>();//组团列表
			//平面图列表
			ProjectImgDto projectImgDto = new ProjectImgDto();
			projectImgDto.setMerchantId(reqDto.getMerchantId());
			projectImgDto.setProjectId(reqDto.getProjectId());
			projectImgDto.setProjectImgType("2");//平面图
			List<ProjectImg> projectImgList = projectImgService.selectListByDto(projectImgDto);
			if(projectImgList.size() > 0){
				for(ProjectImg projectImg : projectImgList){
					FlatMapListRes flatMapListRes = new FlatMapListRes();
					flatMapListRes.setFlatMapUrl(projectImg.getSmallUrl());
					flatMapList.add(flatMapListRes);
				}
				resDto.setFlatMapList(flatMapList);
			}else{
				resDto.setFlatMapList(null);
			}
			//组团列表
			ProjectPremisesDto projectPremisesDto = new ProjectPremisesDto();
			projectPremisesDto.setMerchantId(reqDto.getMerchantId());
			projectPremisesDto.setProjectId(reqDto.getProjectId());
			List<ProjectPremises> projectPremisesList = projectPremisesService.selectListByDto(projectPremisesDto);
			if(projectPremisesList.size() > 0){
				for(ProjectPremises projectPremises : projectPremisesList){
					List<BuildingListRes> buildingList = new ArrayList<BuildingListRes>();//楼栋列表
					PremisesListRes premisesListRes = new PremisesListRes();
					premisesListRes.setPremisesId(String.valueOf(projectPremises.getId()));//组团Id
					premisesListRes.setPremisesName(projectPremises.getGroupName());//组团名称
					
					//楼栋列表
					ProjectBuildingDto projectBuildingDto = new ProjectBuildingDto();
					projectBuildingDto.setMerchantId(projectPremises.getMerchantId());
					projectBuildingDto.setProjectId(projectPremises.getProjectId());
					projectBuildingDto.setPremisesId(projectPremises.getId());
					List<ProjectBuilding> projectBuildingList = projectBuildingService.selectListByDto(projectBuildingDto);
					int soldNum = 0;
					int notSoldNum = 0;
					if(projectBuildingList.size() > 0){
						for(ProjectBuilding projectBuilding : projectBuildingList){
							BuildingListRes buildingListRes = new BuildingListRes();
							buildingListRes.setPremisesId(String.valueOf(projectBuilding.getPremisesId()));//组团Id
							buildingListRes.setBuildingId(String.valueOf(projectBuilding.getId()));//楼栋Id
							buildingListRes.setBuildingName(projectBuilding.getBuildingName());//楼栋名称
							ProjectRoomCount projectRoomCount_build = projectRoomMapper.selectSellCountByRoom(projectBuilding.getMerchantId(), projectBuilding.getProjectId(), projectBuilding.getPremisesId(), projectBuilding.getId());
							if(projectRoomCount_build != null){
								if(Integer.valueOf(projectRoomCount_build.getNotSoldNum()) < 1){
									buildingListRes.setIsSell("0");
								}else{
									buildingListRes.setIsSell("1");
									notSoldNum += Integer.valueOf(projectRoomCount_build.getNotSoldNum());
								}
								soldNum += Integer.valueOf(projectRoomCount_build.getSoldNum());
							}
							buildingList.add(buildingListRes);
						}
						premisesListRes.setBuildingList(buildingList);
					}else{
						premisesListRes.setBuildingList(null);
					}
					//已售数量
					if(soldNum > 0){
						premisesListRes.setSoldNum(String.valueOf(soldNum));
					}else{
						premisesListRes.setSoldNum("0");
					}
					//未售数量
					if(notSoldNum > 0){
						premisesListRes.setNotSoldNum(String.valueOf(notSoldNum));
					}else{
						premisesListRes.setNotSoldNum("0");
					}
					premisesList.add(premisesListRes);
				}
				resDto.setPremisesList(premisesList);
			}else{
				List<BuildingListRes> buildingList = new ArrayList<BuildingListRes>();//楼栋列表
				PremisesListRes premisesListRes = new PremisesListRes();
				//楼栋列表
				ProjectBuildingDto projectBuildingDto = new ProjectBuildingDto();
				projectBuildingDto.setMerchantId(reqDto.getMerchantId());
				projectBuildingDto.setProjectId(reqDto.getProjectId());
				List<ProjectBuilding> projectBuildingList = projectBuildingService.selectListByDto(projectBuildingDto);
				int soldNum = 0;
				int notSoldNum = 0;
				if(projectBuildingList.size() > 0){
					for(ProjectBuilding projectBuilding : projectBuildingList){
						BuildingListRes buildingListRes = new BuildingListRes();
						buildingListRes.setPremisesId(String.valueOf(projectBuilding.getPremisesId()));//组团Id
						buildingListRes.setBuildingId(String.valueOf(projectBuilding.getId()));//楼栋Id
						buildingListRes.setBuildingName(projectBuilding.getBuildingName());//楼栋名称
						ProjectRoomCount projectRoomCount_build = projectRoomMapper.selectSellCountByRoom(projectBuilding.getMerchantId(), projectBuilding.getProjectId(), projectBuilding.getPremisesId(), projectBuilding.getId());
						if(projectRoomCount_build != null){
							if(Integer.valueOf(projectRoomCount_build.getNotSoldNum()) < 1){
								buildingListRes.setIsSell("0");
							}else{
								buildingListRes.setIsSell("1");
								notSoldNum += Integer.valueOf(projectRoomCount_build.getNotSoldNum());
							}
							soldNum += Integer.valueOf(projectRoomCount_build.getSoldNum());
						}
						buildingList.add(buildingListRes);
					}
					premisesListRes.setBuildingList(buildingList);
				}else{
					premisesListRes.setBuildingList(null);
				}
				//已售数量
				if(soldNum > 0){
					premisesListRes.setSoldNum(String.valueOf(soldNum));
				}else{
					premisesListRes.setSoldNum("0");
				}
				//未售数量
				if(notSoldNum > 0){
					premisesListRes.setNotSoldNum(String.valueOf(notSoldNum));
				}else{
					premisesListRes.setNotSoldNum("0");
				}
				premisesList.add(premisesListRes);
				resDto.setPremisesList(premisesList);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询房源列表失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getMarketingControlList:(app查询销控列表接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param product 项目Id
     * @param productCode 项目code
     * @param premisesId 组团Id
     * @param buildingId 楼栋Id
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetMarketingControlListResDto getMarketingControlList(
			GetMarketingControlListReqDto reqDto) {
		GetMarketingControlListResDto resDto = new GetMarketingControlListResDto();
		List<BuildingStatusListRes> buildingStatusList = new ArrayList<BuildingStatusListRes>();//楼栋状态列表
		List<UnitListRes> unitList = new ArrayList<UnitListRes>();//单元列表
		try{
			//组团名称
			ProjectPremises projectPremises = projectPremisesService.selectById(Long.valueOf(reqDto.getPremisesId()));
			if(projectPremises != null){
				resDto.setPremisesName(projectPremises.getGroupName());
			}else{
				resDto.setPremisesName("组团: 未设置");
			}
			//楼栋名称
			ProjectBuilding projectBuilding = projectBuildingService.selectById(Long.valueOf(reqDto.getBuildingId()));
			if(projectBuilding != null){
				resDto.setBuildingName(projectBuilding.getBuildingName());
			}else{
				resDto.setBuildingName("楼栋: 未设置");
			}
			//楼栋状态列表
			List<ProjectRoomCount> projectRoomCountList = projectRoomMapper.selectRoomStatusCountByRoom(reqDto.getMerchantId(), reqDto.getProjectId(), Long.valueOf(reqDto.getBuildingId()));
			if(projectRoomCountList != null && projectRoomCountList.size() > 0){
				for(ProjectRoomCount projectRoomCount : projectRoomCountList){
					BuildingStatusListRes buildingStatusListRes = new BuildingStatusListRes();
					buildingStatusListRes.setBuildingNum(projectRoomCount.getRoomStatusNum());//房间数量
					buildingStatusListRes.setBuildingProportion(projectRoomCount.getAnalysisValuePercentage());//房间占比
					buildingStatusListRes.setBuildingStatus(RoomStatusEnum.getByNo(projectRoomCount.getRoomStatus()).getDes());//房间状态
					buildingStatusList.add(buildingStatusListRes);
				}
				resDto.setBuildingStatusList(buildingStatusList);
			}else{
				BuildingStatusListRes buildingStatusListRes = new BuildingStatusListRes();
				buildingStatusListRes.setBuildingNum("");//房间数量
				buildingStatusListRes.setBuildingProportion("");//房间占比
				buildingStatusListRes.setBuildingStatus("");//房间状态
				buildingStatusList.add(buildingStatusListRes);
				resDto.setBuildingStatusList(buildingStatusList);
			}
			
			//单元列表
			ProjectUnitDto projectUnitDto = new ProjectUnitDto();
			projectUnitDto.setProjectId(reqDto.getProjectId());
			projectUnitDto.setMerchantId(reqDto.getMerchantId());
			projectUnitDto.setPremisesId(Long.valueOf(reqDto.getPremisesId()));
			projectUnitDto.setBuildingId(Long.valueOf(reqDto.getBuildingId()));
			List<ProjectUnit> projectUnitList = projectUnitService.selectListByDto(projectUnitDto);
			//单元是否存在
			if(null != projectUnitList && projectUnitList.size() > 0){
				//循环单元
				for(ProjectUnit projectUnit : projectUnitList){
					UnitListRes unitListRes = new UnitListRes();
					unitListRes.setUnitId(String.valueOf(projectUnit.getId()));//单元Id
					unitListRes.setUnitName(projectUnit.getUnitName());//单元名称
					//楼层列表
					List<ProjectRoomFloorList> floorRoomList = projectRoomMapper.selectFloorListByUnitId(projectUnit.getId());
					//楼层房间列表
					List<FloorListRes> floorList = new ArrayList<FloorListRes>();
					//判断单元楼层是否存在,不存在,直接获取房间
					if(floorRoomList.size() > 0){
						for(ProjectRoomFloorList pr : floorRoomList){
							List<RoomListRes> roomList = new ArrayList<RoomListRes>();//房间列表
							FloorListRes floorListRes = new FloorListRes();
							floorListRes.setFloorNum(String.valueOf(pr.getFloorNum()));
							//房间列表
							ProjectRoomDto projectRoomDto = new ProjectRoomDto();
							projectRoomDto.setUnitId(Long.valueOf(pr.getUnitId()));
							projectRoomDto.setFloor(Integer.parseInt(pr.getFloorNum()));
							List<ProjectRoom> projectRoomList = projectRoomService.selectListByDto(projectRoomDto);
							if(projectRoomList.size() > 0){
								for(ProjectRoom projectRoom : projectRoomList){
									RoomListRes roomListRes = new RoomListRes();
									roomListRes.setRoomId(String.valueOf(projectRoom.getId()));//房间Id
									roomListRes.setRoomName(projectRoom.getRoomName());//房间名称
									roomListRes.setRoomStatus(RoomStatusEnum.getByNo(projectRoom.getRoomStatus()).getDes());//房间状态：销控、未售、认筹、认购、签约、保留、暂不可售
									roomListRes.setCalculateArea(String.valueOf(projectRoom.getBillingArea()+""));//计价面积
									PriceSchemeDetail priceSchemeDetail = priceSchemeDetailService.selectEntityByRoomId(projectRoom.getId());
									if(priceSchemeDetail != null){
										if(priceSchemeDetail.getTotalPrice() != null && !"".equals(priceSchemeDetail.getTotalPrice())){
											DecimalFormat formater = new DecimalFormat("###,###,###,###");
											roomListRes.setDiscountTotalPrice(formater.format(priceSchemeDetail.getTotalPrice()));
										}else{
											roomListRes.setDiscountTotalPrice(null);
										}
									}
									roomList.add(roomListRes);
								}
								floorListRes.setRoomList(roomList);
							}else{
								floorListRes.setRoomList(null);
							}
							floorList.add(floorListRes);
						}
						unitListRes.setFloorList(floorList);
					}else{
						unitListRes.setUnitId("");//单元Id
						unitListRes.setUnitName("单元: 未设置");//单元名称
						floorList = new ArrayList<FloorListRes>();//房间列表
						List<RoomListRes> roomList = new ArrayList<RoomListRes>();//房间列表
						FloorListRes floorListRes = new FloorListRes();
						//没有楼层,默认给1
						floorListRes.setFloorNum("1");
						//房间列表
						ProjectRoomDto projectRoomDto = new ProjectRoomDto();
						projectRoomDto.setMerchantId(reqDto.getMerchantId());
						projectRoomDto.setProjectId(reqDto.getProjectId());
						projectRoomDto.setPremisesId(Long.valueOf(reqDto.getPremisesId()));
						projectRoomDto.setBuildingId(Long.valueOf(reqDto.getBuildingId()));
						List<ProjectRoom> projectRoomList = projectRoomService.selectListByDto(projectRoomDto);
						if(projectRoomList.size() > 0){
							for(ProjectRoom projectRoom : projectRoomList){
								RoomListRes roomListRes = new RoomListRes();
								roomListRes.setRoomId(String.valueOf(projectRoom.getId()));//房间Id
								roomListRes.setRoomName(projectRoom.getRoomName());//房间名称
								roomListRes.setRoomStatus(RoomStatusEnum.getByNo(projectRoom.getRoomStatus()).getDes());//房间状态：销控、未售、认筹、认购、签约、保留、暂不可售
								roomListRes.setCalculateArea(String.valueOf(projectRoom.getBillingArea()+""));//计价面积
								PriceSchemeDetail priceSchemeDetail = priceSchemeDetailService.selectEntityByRoomId(projectRoom.getId());
								if(priceSchemeDetail != null){
									if(priceSchemeDetail.getTotalPrice() != null && !"".equals(priceSchemeDetail.getTotalPrice())){
										DecimalFormat formater = new DecimalFormat("###,###,###,###");
										roomListRes.setDiscountTotalPrice(formater.format(priceSchemeDetail.getTotalPrice()));
									}else{
										roomListRes.setDiscountTotalPrice(null);
									}
								}
								roomList.add(roomListRes);
							}
						}
						floorListRes.setRoomList(roomList);
						floorList.add(floorListRes);
						unitListRes.setFloorList(floorList);
					}
					unitList.add(unitListRes);
				}
				resDto.setUnitList(unitList);
			}else{
				UnitListRes unitListRes = new UnitListRes();
				unitListRes.setUnitId("");//单元Id
				unitListRes.setUnitName("单元: 未设置");//单元名称
				
				List<FloorListRes> floorList = new ArrayList<FloorListRes>();//房间列表
				List<RoomListRes> roomList = new ArrayList<RoomListRes>();//房间列表
				FloorListRes floorListRes = new FloorListRes();
				//没有楼层,默认给1
				floorListRes.setFloorNum("1");
				//房间列表
				ProjectRoomDto projectRoomDto = new ProjectRoomDto();
				projectRoomDto.setMerchantId(reqDto.getMerchantId());
				projectRoomDto.setProjectId(reqDto.getProjectId());
				projectRoomDto.setPremisesId(Long.valueOf(reqDto.getPremisesId()));
				projectRoomDto.setBuildingId(Long.valueOf(reqDto.getBuildingId()));
				List<ProjectRoom> projectRoomList = projectRoomService.selectListByDto(projectRoomDto);
				if(projectRoomList.size() > 0){
					for(ProjectRoom projectRoom : projectRoomList){
						RoomListRes roomListRes = new RoomListRes();
						roomListRes.setRoomId(String.valueOf(projectRoom.getId()));//房间Id
						roomListRes.setRoomName(projectRoom.getRoomName());//房间名称
						roomListRes.setRoomStatus(RoomStatusEnum.getByNo(projectRoom.getRoomStatus()).getDes());//房间状态：销控、未售、认筹、认购、签约、保留、暂不可售
						roomListRes.setCalculateArea(String.valueOf(projectRoom.getBillingArea()+""));//计价面积
						PriceSchemeDetail priceSchemeDetail = priceSchemeDetailService.selectEntityByRoomId(projectRoom.getId());
						if(priceSchemeDetail != null){
							if(priceSchemeDetail.getTotalPrice() != null && !"".equals(priceSchemeDetail.getTotalPrice())){
								DecimalFormat formater = new DecimalFormat("###,###,###,###");
								roomListRes.setDiscountTotalPrice(formater.format(priceSchemeDetail.getTotalPrice()));
							}else{
								roomListRes.setDiscountTotalPrice(null);
							}
						}
						roomList.add(roomListRes);
					}
				}
				floorListRes.setRoomList(roomList);
				floorList.add(floorListRes);
				unitListRes.setFloorList(floorList);
				unitList.add(unitListRes);
				resDto.setUnitList(unitList);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询销控列表失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getHousesDetail:(app查询房源详情接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param product 项目Id
     * @param productCode 项目code
     * @param roomId 房间Id
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetHousesDetailResDto getHousesDetail(GetHousesDetailReqDto reqDto) {
		GetHousesDetailResDto resDto = new GetHousesDetailResDto();
		List<RealMapListRes> realMapList = new ArrayList<RealMapListRes>();
		try{
			ProjectRoom projectRoom = projectRoomService.selectById(Long.valueOf(reqDto.getRoomId()));
			if(projectRoom != null){
				//根据房间Id获取客户姓名和经纪人
				getCustomerByRoomId(resDto, projectRoom.getId(), projectRoom.getRoomStatus());
				resDto.setHousesName(projectRoom.getCombinedName());//房源名称
				resDto.setHousesStatus(RoomStatusEnum.getByNo(projectRoom.getRoomStatus()).getDes());//房源状态
				//计价方式
				PriceScheme priceScheme = priceSchemeMapper.selectEntityByRoomId(Long.valueOf(reqDto.getRoomId()));
				PriceSchemeDetail priceSchemeDetail = priceSchemeDetailMapper.selectEntityByRoomId(Long.valueOf(reqDto.getRoomId()));
				if(priceScheme != null){
					if(priceScheme.getValuationType() != null && !"".equals(priceScheme.getValuationType())){
						if("1".equals(priceScheme.getValuationType())){
							resDto.setPricingMode("建筑面积");
							if(priceSchemeDetail != null && priceSchemeDetail.getUnitPrice() != null){
								resDto.setBuildingPrice(String.valueOf(priceSchemeDetail.getUnitPrice()));//建筑单价
							}else{
								resDto.setBuildingPrice("0");//建筑单价
							}
							resDto.setInnerPrice("0");//套内单价
						}else if("2".equals(priceScheme.getValuationType())){
							resDto.setPricingMode("套内面积");
							resDto.setBuildingPrice("0");//建筑单价
							if(priceSchemeDetail != null && priceSchemeDetail.getUnitPrice() != null){
								resDto.setInnerPrice(String.valueOf(priceSchemeDetail.getUnitPrice()));//套内单价
							}else{
								resDto.setInnerPrice("0");//套内单价
							}
						}else if("3".equals(priceScheme.getValuationType())){
							resDto.setPricingMode("别墅/排屋");
							resDto.setBuildingPrice("0");//建筑单价
							resDto.setInnerPrice("0");//套内单价
						}else if("4".equals(priceScheme.getValuationType())){
							resDto.setPricingMode("车位");
							resDto.setBuildingPrice("0");//建筑单价
							resDto.setInnerPrice("0");//套内单价
						}
					}else{
						resDto.setPricingMode(null);
					}
				}
				//户型
				ProjectHouseType projectHouseType = projectHouseTypeService.selectById(projectRoom.getHouseTypeId());
				if(projectHouseType != null){
					if(projectHouseType.getHouseTypeName() != null && !"".equals(projectHouseType.getHouseTypeName())){
						resDto.setHousesType(projectHouseType.getHouseTypeName());
					}else{
						resDto.setHousesType(null);
					}
				}
				//建筑面积
				if(projectRoom.getBuildingArea() != null && !"".equals(projectRoom.getBuildingArea())){
					resDto.setBuildingArea(String.valueOf(projectRoom.getBuildingArea()));
				}else{
					resDto.setBuildingArea(null);
				}
				//套内面积
				if(projectRoom.getInnerArea() != null && !"".equals(projectRoom.getInnerArea())){
					resDto.setInnerArea(String.valueOf(projectRoom.getInnerArea()));
				}else{
					resDto.setInnerArea(null);
				}
				//分摊面积
				if(projectRoom.getSharingArea() != null && !"".equals(projectRoom.getSharingArea())){
					resDto.setSharingArea(String.valueOf(projectRoom.getSharingArea()));
				}else{
					resDto.setSharingArea(null);
				}
				//赠送面积
				if(projectRoom.getFreeArea() != null && !"".equals(projectRoom.getFreeArea())){
					resDto.setFreeArea(String.valueOf(projectRoom.getFreeArea()));
				}else{
					resDto.setFreeArea(null);
				}
				//总价（取价格方案表中总价）
				if(priceSchemeDetail != null){
					if(priceSchemeDetail.getTotalPrice() !=null && !"".equals(priceSchemeDetail.getTotalPrice())){
						String totalPrice = df.format(Double.valueOf(String.valueOf(priceSchemeDetail.getTotalPrice()))/10000);
						resDto.setTotalAmount(totalPrice);
					}else{
						resDto.setTotalAmount(null);
					}
				}else{
					resDto.setTotalAmount(null);
				}
				
				//实景图
				ProjectImgDto projectImgDto = new ProjectImgDto();
				projectImgDto.setMerchantId(reqDto.getMerchantId());
				projectImgDto.setProjectId(reqDto.getProjectId());
				projectImgDto.setProjectImgType("5");//类型：实景图
				List<ProjectImg> projectImgList = projectImgService.selectListByDto(projectImgDto);
				if(projectImgList.size() > 0){
					for(ProjectImg projectImg : projectImgList){
						RealMapListRes realMapListRes = new RealMapListRes();
						realMapListRes.setRealMapId(String.valueOf(projectImg.getId()));//实景图Id
						realMapListRes.setRealMapUrl(projectImg.getSmallUrl());//实景图（小）
						realMapList.add(realMapListRes);
					}
					resDto.setRealMapList(realMapList);
				}else{
					resDto.setRealMapList(null);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询房源详情失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}
	
	/**
	 * 根据房间号获取客户信息
	 * @param resDto
	 * @param roomId
	 * @param roomStatus 房间状态
	 */
	private void getCustomerByRoomId(GetHousesDetailResDto resDto, 
			Long roomId, String roomStatus) {
		if(roomStatus.equals(RoomStatusEnum.SIGN.getNo())) {
			SignedDto signedDto = signedService.getCustomerByRoomId(roomId);
			if(signedDto != null) {
				resDto.setCustomerName(signedDto.getCustomerName());
				resDto.setUserName(signedDto.getUserName());
			}
		}else if(roomStatus.equals(RoomStatusEnum.BUY.getNo())) {
			SubscribeDto dto = subscribeService.getCustomerByRoomId(roomId);
			if(dto != null) {
				resDto.setCustomerName(dto.getCustomerName());
				resDto.setUserName(dto.getUserName());
			}
		}
	}

	/**
     * addProjectRealMap:(app新增项目实景图接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param product 项目Id
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @param realMapList（实景图列表）
     * @return 
     */
	@Override
	public AddProjectRealMapResDto addProjectRealMap(
			AddProjectRealMapReqDto reqDto) {
		AddProjectRealMapResDto resDto = new AddProjectRealMapResDto();
		try{
			List<RealMapListRes> realMapList = reqDto.getRealMapList();
			if(realMapList != null){
				for(RealMapListRes realMapListRes : realMapList){
					String imgName = SequencesGenerator.getUUID("IMG")+realMapListRes.getRealMapType();
					String result=FileUploadPorxyUtil.appPost(fileUploadUrl,realMapListRes.getRealMapContent(),imgName);
					JSONObject resultJson=JSON.parseObject(result);
					String postResult=resultJson.getString("result");
					if(!"1".equals(postResult)){
						resDto.setResult(ResultEnum.FAILURE.getNo());
						resDto.setErrorCode("00000");
						resDto.setErrorMsg("新增项目实景图上传失败");
						return resDto;
					}
					String postUrl=resultJson.getString("url");
					ProjectImgDto projectImgDto = new ProjectImgDto();
					projectImgDto.setProjectImgCode("projectCode");
					projectImgDto.setProjectId(reqDto.getProjectId());
					projectImgDto.setProjectCode(reqDto.getProjectCode());
					projectImgDto.setMerchantId(Long.valueOf(reqDto.getMerchantId()));
					User user = userService.selectById(Long.valueOf(reqDto.getUserId()));
					projectImgDto.setUserCode(user.getUserCode());
					projectImgDto.setAccessCode(reqDto.getProjectCode());
					projectImgDto.setLargeUrl(postUrl);
					projectImgDto.setNormalUrl(postUrl);
					projectImgDto.setSmallUrl(postUrl);
					projectImgDto.setProjectImgType("5");
					projectImgDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
					projectImgDto.setCreateUserId(Long.valueOf(reqDto.getUserId()));
					projectImgService.create(projectImgDto);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("新增项目实景图失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * delProjectRealMap:(app删除项目实景图接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param product 项目Id
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @param realMapList（实景图列表）
     * @return 
     */
	@Override
	public DelProjectRealMapResDto delProjectRealMap(
			DelProjectRealMapReqDto reqDto) {
		DelProjectRealMapResDto resDto = new DelProjectRealMapResDto();
		try{
			List<RealMapListRes> realMapList = reqDto.getRealMapList();
			if(realMapList != null){
				for(RealMapListRes realMapListRes : realMapList){
					ProjectImgDto projectImgDto = new ProjectImgDto();
					projectImgDto.setId(Long.valueOf(realMapListRes.getRealMapId()));
					projectImgDto.setDelFlag(DelFlagEnum.DEL.getNo());
					projectImgDto.setUpdateTime(new Date());
					projectImgDto.setUpdateUserId(Long.valueOf(reqDto.getUserId()));
					projectImgService.update(projectImgDto);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("删除项目实景图失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getSalesTargetList:(app查询销售指标接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param targetType 指标类型：1 销售指标；2、资金回笼指标
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetSalesTargetListResDto getSalesTargetList(
			GetSalesTargetListReqDto reqDto) {
		GetSalesTargetListResDto resDto = new GetSalesTargetListResDto();
		List<SalesTargetListRes> monthTargetList = new ArrayList<SalesTargetListRes>();//月指标数列表
		List<SalesTargetListRes> targetCompleteList = new ArrayList<SalesTargetListRes>();//月指标完成数列表
		List<SalesTargetListRes> monthTotalTargetList = new ArrayList<SalesTargetListRes>();//累计月指标列表
		List<SalesTargetListRes> monthTotalCompletetList = new ArrayList<SalesTargetListRes>();//累计月完成数列表
		try{
			//月指标数
			String targetType = null;
			if("1".equals(reqDto.getTargetType())){
				targetType = "0";
			}else{
				targetType = "1";
			}
			SalesTargetCount salesTargetCount = projectMapper.selectMonthTargetCount(reqDto.getMerchantId(), reqDto.getProjectCode(), targetType);
			if(salesTargetCount != null){
				if(salesTargetCount.getJanuaryValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getJanuaryValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getFebruaryValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getFebruaryValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getMarchValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getMarchValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getAprilValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getAprilValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getMayValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getMayValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getJuneValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getJuneValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getJulyValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getJulyValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getAugustValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getAugustValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getSeptemberValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getSeptemberValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getOctoberValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getOctoberValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getNovemberValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getNovemberValue())/10000));
					monthTargetList.add(st_res);
				}
				if(salesTargetCount.getDecemberValue() != null){
					SalesTargetListRes st_res = new SalesTargetListRes();
					st_res.setTargetNum(df.format(Double.valueOf(salesTargetCount.getDecemberValue())/10000));
					monthTargetList.add(st_res);
				}
				resDto.setMonthTargetList(monthTargetList);
			}else{
				resDto.setMonthTargetList(null);
			}
			
			//累月指标数
			SalesTargetCount salesTotalTargetCount = projectMapper.selectMonthTotalTargetCount(reqDto.getMerchantId(), reqDto.getProjectCode(), targetType);
			if(salesTotalTargetCount != null){
				if(salesTargetCount.getJanuaryValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getJanuaryValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getFebruaryValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getFebruaryValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getMarchValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getMarchValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getAprilValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getAprilValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getMayValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getMayValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getJuneValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getJuneValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getJulyValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getJulyValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getAugustValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getAugustValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getSeptemberValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getSeptemberValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getOctoberValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getOctoberValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getNovemberValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getNovemberValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				if(salesTargetCount.getDecemberValue() != null){
					SalesTargetListRes stTotal_res = new SalesTargetListRes();
					stTotal_res.setMt_targetNum(df.format(Double.valueOf(salesTotalTargetCount.getDecemberValue())/10000));
					monthTotalTargetList.add(stTotal_res);
				}
				resDto.setMonthTotalTargetList(monthTotalTargetList);
			}else{
				resDto.setMonthTotalTargetList(null);
			}
			
			/**
			 * 指标类型：1、签约数；2、财务收款数
			 */
			if("1".equals(reqDto.getTargetType())){
				//月指标完成数（签约数）
				List<SalesTargetCount> salesTargetCompleteCountList = projectMapper.selectMonthTargetCompleteCount(reqDto.getMerchantId(), reqDto.getProjectCode());
				if(salesTargetCompleteCountList != null){
					Map<String, String> map = new HashMap<String, String>();
					for(SalesTargetCount st_list :salesTargetCompleteCountList){
						map.put(st_list.getSignedMonths(), st_list.getSignedMonthsValue());
					}
					for(int i=1;i<13;i++){
						SalesTargetListRes stComplete_res = new SalesTargetListRes();
						String s = String.valueOf(i);
						if(i < 10){
							s = "0"+s;
						}
						if(map.get(s) != null && !"".equals(map.get(s))){
							stComplete_res.setCompleteNum(df.format(Double.valueOf(map.get(s))/10000));
						}else{
							stComplete_res.setCompleteNum("0");
						}
						targetCompleteList.add(stComplete_res);
					}
					resDto.setTargetCompleteList(targetCompleteList);
				}else{
					resDto.setTargetCompleteList(null);
				}
				
				//累月指标完成数（签约数）
				List<SalesTargetCount> salesTotalTargetCompleteCountList = projectMapper.selectMonthTotalTargetCompleteCount(reqDto.getMerchantId(), reqDto.getProjectCode());
				if(salesTotalTargetCompleteCountList != null){
					Double tc_sum = 0.0;
					Map<String, String> map = new HashMap<String, String>();
					for(SalesTargetCount stTotal_list :salesTotalTargetCompleteCountList){
						map.put(stTotal_list.getSignedMonths(), stTotal_list.getSignedMonthsValue());
					}
					for(int i=1;i<13;i++){
						SalesTargetListRes stTotalComplete_res = new SalesTargetListRes();
						String s = String.valueOf(i);
						if(i < 10){
							s = "0"+s;
						}
						if(map.get(s) != null && !"".equals(map.get(s))){
							tc_sum += Double.valueOf(map.get(s));
							stTotalComplete_res.setMt_completeNum(df.format(Double.valueOf(tc_sum)/10000));
						}else{
							if(!"0.0".equals(String.valueOf(tc_sum))){
								stTotalComplete_res.setMt_completeNum(df.format(Double.valueOf(tc_sum)/10000));
							}else{
								stTotalComplete_res.setMt_completeNum("0");
							}
						}
						monthTotalCompletetList.add(stTotalComplete_res);
					}
					resDto.setMonthTotalCompletetList(monthTotalCompletetList);
				}else{
					resDto.setMonthTotalCompletetList(null);
				}
			}else{
				//月指标完成数（财务收款数）
				List<SalesTargetCount> salesRefundTargetCompleteCountList = projectMapper.selectRefundMonthTargetCompleteCount(reqDto.getMerchantId(), reqDto.getProjectCode());
				if(salesRefundTargetCompleteCountList != null){
					Map<String, String> map = new HashMap<String, String>();
					for(SalesTargetCount stRefund_list :salesRefundTargetCompleteCountList){
						map.put(stRefund_list.getRefundMonths(), stRefund_list.getRefundMonthsValue());
					}
					for(int i=1;i<13;i++){
						SalesTargetListRes stRefundComplete_res = new SalesTargetListRes();
						String s = String.valueOf(i);
						if(i < 10){
							s = "0"+s;
						}
						if(map.get(s) != null && !"".equals(map.get(s))){
							stRefundComplete_res.setCompleteNum(df.format(Double.valueOf(map.get(s))/10000));
						}else{
							stRefundComplete_res.setCompleteNum("0");
						}
						targetCompleteList.add(stRefundComplete_res);
					}
					resDto.setTargetCompleteList(targetCompleteList);
				}else{
					resDto.setTargetCompleteList(null);
				}
				
				//累月指标完成数（财务收款数）
				List<SalesTargetCount> salesRefundTotalTargetCompleteCountList = projectMapper.selectRefundMonthTotalTargetCompleteCount(reqDto.getMerchantId(), reqDto.getProjectCode());
				if(salesRefundTotalTargetCompleteCountList != null){
					Double tcRefund_sum = 0.0;
					Map<String, String> map = new HashMap<String, String>();
					for(SalesTargetCount stRefundTotal_list :salesRefundTotalTargetCompleteCountList){
						map.put(stRefundTotal_list.getRefundMonths(), stRefundTotal_list.getRefundMonthsValue());
					}
					for(int i=1;i<13;i++){
						SalesTargetListRes stRefundTotalComplete_res = new SalesTargetListRes();
						String s = String.valueOf(i);
						if(i < 10){
							s = "0"+s;
						}
						if(map.get(s) != null && !"".equals(map.get(s))){
							tcRefund_sum += Double.valueOf(map.get(s));
							stRefundTotalComplete_res.setMt_completeNum(df.format(Double.valueOf(tcRefund_sum)/10000));
						}else{
							if(!"0.0".equals(String.valueOf(tcRefund_sum))){
								stRefundTotalComplete_res.setMt_completeNum(df.format(Double.valueOf(tcRefund_sum)/10000));
							}else{
								stRefundTotalComplete_res.setMt_completeNum("0");
							}
						}
						monthTotalCompletetList.add(stRefundTotalComplete_res);
					}
					resDto.setMonthTotalCompletetList(monthTotalCompletetList);
				}else{
					resDto.setMonthTotalCompletetList(null);
				}
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询销售指标失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getPriceRecordList:(app查询算价分析接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param workloadTimeType 工作量时间类型：1、今天（默认）；2、昨天；3、本周；4、上周；5、本月；6、上月；7、近三月；8、全部
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetPriceRecordListResDto getPriceRecordList(
			GetPriceRecordListReqDto reqDto) {
		GetPriceRecordListResDto resDto = new GetPriceRecordListResDto();
		List<HouseTypeListRes> houseTypeList = new ArrayList<HouseTypeListRes>();//户型列表
		List<PropertyTypeListRes> propertyTypeList = new ArrayList<PropertyTypeListRes>();//物业类型列表
		try{
			CustomerCountDto customerCountDto = new CustomerCountDto();
			customerCountDto.setMerchantId(String.valueOf(reqDto.getMerchantId()));
			customerCountDto.setProjectCode(reqDto.getProjectCode());
			customerCountDto.setTimeType(reqDto.getWorkloadTimeType());
			List<PriceRecordCount> prht_list= projectMapper.selectPriceRecordHouseTypeCount(customerCountDto);//户型列表
			List<PriceRecordCount> prpt_list = projectMapper.selectPriceRecordPropertyTypeCount(customerCountDto);//物业类别列表
			//户型
			if(prht_list != null){
				for(PriceRecordCount prc_houseType : prht_list){
					HouseTypeListRes houseTypeListRes = new HouseTypeListRes();
					houseTypeListRes.setHouseTypeName(prc_houseType.getHouseTypeName());//户型名称
					houseTypeListRes.setHouseTypeNum(prc_houseType.getHouseTypeNum());//户型统计数量
					houseTypeList.add(houseTypeListRes);
				}
				resDto.setHouseTypeList(houseTypeList);
			}else{
				resDto.setHouseTypeList(null);
			}
			//物业类别
			if(prpt_list != null){
				for(PriceRecordCount prc_propertyType : prpt_list){
					PropertyTypeListRes propertyTypeListRes = new PropertyTypeListRes();
					propertyTypeListRes.setPropertyTypeName(prc_propertyType.getPropertyTypeName());//物业类别名称
					propertyTypeListRes.setPropertyTypeNum(prc_propertyType.getPropertyTypeNum());//物业类别统计数量
					propertyTypeList.add(propertyTypeListRes);
				}
				resDto.setPropertyTypeList(propertyTypeList);
			}else{
				resDto.setPropertyTypeList(null);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询算价分析失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getDealHouseList:(app查询成交房源分析接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param houseType 房源类型：1、住宅；2、别墅；3、车位
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetDealHouseListResDto getDealHouseList(GetDealHouseListReqDto reqDto) {
		GetDealHouseListResDto resDto = new GetDealHouseListResDto();
		List<GetDealHouseListRes> areaSegmentList = new ArrayList<GetDealHouseListRes>();//面积段列表
		List<GetDealHouseListRes> lumpSumList = new ArrayList<GetDealHouseListRes>();//总价段列表
		try{
			//面积
			List<DealHouseCount> selectDealHouseAreaCount = projectMapper.selectDealHouseAreaCount(reqDto.getMerchantId(), reqDto.getProjectCode(), reqDto.getHouseType());
			if(selectDealHouseAreaCount != null){
				for(DealHouseCount dealHouseCount : selectDealHouseAreaCount){
					GetDealHouseListRes getDealHouseListRes = new GetDealHouseListRes();
					if(dealHouseCount.getAreaSegment() != null && !"".equals(dealHouseCount.getAreaSegment())){
						getDealHouseListRes.setAreaSegment(dealHouseCount.getAreaSegment());//面积名称
						getDealHouseListRes.setAreaSegmentNum(dealHouseCount.getAreaSegmentNum());//面积数量
						areaSegmentList.add(getDealHouseListRes);
					}
				}
				resDto.setAreaSegmentList(areaSegmentList);
			}else{
				resDto.setAreaSegmentList(null);
			}
			//总价
			List<DealHouseCount> selectDealHousePriceCount = projectMapper.selectDealHousePriceCount(reqDto.getMerchantId(), reqDto.getProjectCode(), reqDto.getHouseType());
			if(selectDealHousePriceCount != null){
				for(DealHouseCount dealHouseCount_zj : selectDealHousePriceCount){
					GetDealHouseListRes getDealHouseListRes_zj = new GetDealHouseListRes();
					if(dealHouseCount_zj.getLumpSum() != null && !"".equals(dealHouseCount_zj.getLumpSum())){
						getDealHouseListRes_zj.setLumpSum(dealHouseCount_zj.getLumpSum());//总价名称
						getDealHouseListRes_zj.setLumpSumNum(dealHouseCount_zj.getLumpSumNum());//总价数量
						lumpSumList.add(getDealHouseListRes_zj);
					}
				}
				resDto.setLumpSumList(lumpSumList);
			}else{
				resDto.setLumpSumList(null);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询成交房源分析失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getStockHouseList:(app查询存量房源分析接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param houseType 房源类型：1、住宅；2、别墅；3、车位
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetStockHouseListResDto getStockHouseList(
			GetStockHouseListReqDto reqDto) {
		GetStockHouseListResDto resDto = new GetStockHouseListResDto();
		List<GetDealHouseListRes> areaSegmentList = new ArrayList<GetDealHouseListRes>();//面积段列表
		List<GetDealHouseListRes> lumpSumList = new ArrayList<GetDealHouseListRes>();//总价段列表
		try{
			//面积
			List<DealHouseCount> selectDealHouseAreaCount = projectMapper.selectStockHouseAreaCount(reqDto.getMerchantId(), reqDto.getProjectCode(), reqDto.getHouseType());
			if(selectDealHouseAreaCount != null){
				for(DealHouseCount dealHouseCount : selectDealHouseAreaCount){
					GetDealHouseListRes getDealHouseListRes = new GetDealHouseListRes();
					if(dealHouseCount.getAreaSegment() != null && !"".equals(dealHouseCount.getAreaSegment())){
						getDealHouseListRes.setAreaSegment(dealHouseCount.getAreaSegment());//面积名称
						getDealHouseListRes.setAreaSegmentNum(dealHouseCount.getAreaSegmentNum());//面积数量
						areaSegmentList.add(getDealHouseListRes);
					}
				}
				resDto.setAreaSegmentList(areaSegmentList);
			}else{
				resDto.setAreaSegmentList(null);
			}
			//总价
			List<DealHouseCount> selectDealHousePriceCount = projectMapper.selectStockHousePriceCount(reqDto.getMerchantId(), reqDto.getProjectCode(), reqDto.getHouseType());
			if(selectDealHousePriceCount != null){
				for(DealHouseCount dealHouseCount_zj : selectDealHousePriceCount){
					GetDealHouseListRes getDealHouseListRes_zj = new GetDealHouseListRes();
					if(dealHouseCount_zj.getLumpSum() != null && !"".equals(dealHouseCount_zj.getLumpSum())){
						getDealHouseListRes_zj.setLumpSum(dealHouseCount_zj.getLumpSum());//总价名称
						getDealHouseListRes_zj.setLumpSumNum(dealHouseCount_zj.getLumpSumNum());//总价数量
						lumpSumList.add(getDealHouseListRes_zj);
					}
				}
				resDto.setLumpSumList(lumpSumList);
			}else{
				resDto.setLumpSumList(null);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询存量房源分析失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getDealHouseTypeList:(app查询成交房源类型分析接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param workloadTimeType 工作量时间类型：1、今天（默认）；2、昨天；3、本周；4、上周；5、本月；6、上月；7、近三月；8、今年
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetDealHouseTypeListResDto getDealHouseTypeList(
			GetDealHouseTypeListReqDto reqDto) {
		GetDealHouseTypeListResDto resDto = new GetDealHouseTypeListResDto();
		List<DealHouseTypeListRes> dealHouseTypeList = new ArrayList<DealHouseTypeListRes>();
		try{
			CustomerCountDto customerCountDto = new CustomerCountDto();
			customerCountDto.setProjectCode(reqDto.getProjectCode());
			customerCountDto.setMerchantId(String.valueOf(reqDto.getMerchantId()));
			customerCountDto.setTimeType(reqDto.getWorkloadTimeType());
			List<DealHouseCount> selectDealHouseTypeList = projectMapper.selectDealHouseTypeCount(customerCountDto);
			if(selectDealHouseTypeList.size() > 0){
				for(DealHouseCount dealHouseCount : selectDealHouseTypeList){
					DealHouseTypeListRes dealHouseTypeListRes = new DealHouseTypeListRes();
					if(dealHouseCount != null){
						if(dealHouseCount.getDealHouseTypeName() != null && !"".equals(dealHouseCount.getDealHouseTypeName())){
							dealHouseTypeListRes.setDealHouseTypeName(PropertyTypeEnum.getByNo(dealHouseCount.getDealHouseTypeName()).getDes());//成交房产类型名称
							dealHouseTypeListRes.setDealHouseTypeNum(dealHouseCount.getDealHouseTypeNum());//成交房产类型数
							dealHouseTypeList.add(dealHouseTypeListRes);
						}
					}
				}
				if(dealHouseTypeList.size() > 0){
					resDto.setDealHouseTypeList(dealHouseTypeList);
				}else{
					resDto.setDealHouseTypeList(null);
				}
			}else{
				resDto.setDealHouseTypeList(null);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询成交房源类型分析失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getDealHouseTypeList:(app查询存量时间分析接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param monthlyLimit 月份界限:1个月 对应入参为‘1’....以此类推：24个月对应入参‘24’
     * @param propertyType 房产类型：1、公寓；2、别墅；3、车位
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetStockTimeListResDto getStockTimeList(GetStockTimeListReqDto reqDto) {
		GetStockTimeListResDto resDto = new GetStockTimeListResDto();
		List<GetStockTimeListRes> stockTimeList = new ArrayList<GetStockTimeListRes>();//存量时间列表
		int monthDay = 30; //每个月天数
		try{
			
			if(Integer.parseInt(reqDto.getMonthlyLimit()) > 0 && Integer.parseInt(reqDto.getMonthlyLimit()) <= 6){
				CustomerCountDto customerCountDto = new CustomerCountDto();
				customerCountDto.setProjectCode(reqDto.getProjectCode());
				customerCountDto.setMerchantId(String.valueOf(reqDto.getMerchantId()));
				customerCountDto.setPropertyType(reqDto.getPropertyType());
				List<DealHouseCount> selectStockTimeList = projectMapper.selectStockTimeCount(customerCountDto);
				int m = 0,n=0;
					GetStockTimeListRes getStockTimeListRes = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes2 = new GetStockTimeListRes();
					for(DealHouseCount dealHouseCount : selectStockTimeList){
						if(Integer.parseInt(reqDto.getMonthlyLimit())*monthDay >= Integer.parseInt(dealHouseCount.getStockTimeName())){
							m+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量房源数
						}else{
							n+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量房源数
						}
					}
					if(m > 0){
						getStockTimeListRes.setStockTimeName("0~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes.setStockTimeNum(String.valueOf(m));
						stockTimeList.add(getStockTimeListRes);
					}else{
						getStockTimeListRes.setStockTimeName("0~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes);
					}
					if(n > 0){
						getStockTimeListRes2.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes2.setStockTimeNum(String.valueOf(n));
						stockTimeList.add(getStockTimeListRes2);
					}else{
						getStockTimeListRes2.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes2.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes2);
					}
					resDto.setStockTimeList(stockTimeList);
			} else if(Integer.parseInt(reqDto.getMonthlyLimit()) > 6 && Integer.parseInt(reqDto.getMonthlyLimit()) <= 12){
				CustomerCountDto customerCountDto = new CustomerCountDto();
				customerCountDto.setProjectCode(reqDto.getProjectCode());
				customerCountDto.setMerchantId(String.valueOf(reqDto.getMerchantId()));
				customerCountDto.setPropertyType(reqDto.getPropertyType());
				List<DealHouseCount> selectStockTimeList = projectMapper.selectStockTimeCount(customerCountDto);
				int m = 0,n=0,s=0;
					GetStockTimeListRes getStockTimeListRes = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes2 = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes3 = new GetStockTimeListRes();
					for(DealHouseCount dealHouseCount : selectStockTimeList){
						if(Integer.parseInt(dealHouseCount.getStockTimeName()) >= 0 && Integer.parseInt(dealHouseCount.getStockTimeName()) <= 6*monthDay){
							m+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else if(Integer.parseInt(dealHouseCount.getStockTimeName()) > 6*monthDay && Integer.parseInt(reqDto.getMonthlyLimit())*monthDay <= Integer.parseInt(dealHouseCount.getStockTimeName())){
							n+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else{
							s+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}
					}
					if(m > 0){
						getStockTimeListRes.setStockTimeName("0~6个月");
						getStockTimeListRes.setStockTimeNum(String.valueOf(m));
						stockTimeList.add(getStockTimeListRes);
					}else{
						getStockTimeListRes.setStockTimeName("0~6个月");
						getStockTimeListRes.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes);
					}
					if(n > 0){
						getStockTimeListRes2.setStockTimeName("6~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes2.setStockTimeNum(String.valueOf(n));
						stockTimeList.add(getStockTimeListRes2);
					}else{
						getStockTimeListRes2.setStockTimeName("6~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes2.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes2);
					}
					if(s > 0){
						getStockTimeListRes3.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes3.setStockTimeNum(String.valueOf(s));
						stockTimeList.add(getStockTimeListRes3);
					}else{
						getStockTimeListRes3.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes3.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes3);
					}
					resDto.setStockTimeList(stockTimeList);
			} else if(Integer.parseInt(reqDto.getMonthlyLimit()) > 12 && Integer.parseInt(reqDto.getMonthlyLimit()) <= 18){
				CustomerCountDto customerCountDto = new CustomerCountDto();
				customerCountDto.setProjectCode(reqDto.getProjectCode());
				customerCountDto.setMerchantId(String.valueOf(reqDto.getMerchantId()));
				customerCountDto.setPropertyType(reqDto.getPropertyType());
				List<DealHouseCount> selectStockTimeList = projectMapper.selectStockTimeCount(customerCountDto);
				int m = 0,n=0,s=0,d=0;
					GetStockTimeListRes getStockTimeListRes = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes2 = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes3 = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes4 = new GetStockTimeListRes();
					for(DealHouseCount dealHouseCount : selectStockTimeList){
						if(Integer.parseInt(dealHouseCount.getStockTimeName()) >= 0 && Integer.parseInt(dealHouseCount.getStockTimeName()) <= 6*monthDay){
							m+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else if(Integer.parseInt(dealHouseCount.getStockTimeName()) > 6*monthDay && Integer.parseInt(dealHouseCount.getStockTimeName()) <= 12*monthDay){
							n+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else if(Integer.parseInt(dealHouseCount.getStockTimeName()) > 12*monthDay && Integer.parseInt(reqDto.getMonthlyLimit()) >= Integer.parseInt(dealHouseCount.getStockTimeName())){
							s+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else{
							d+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}
					}
					if(m > 0){
						getStockTimeListRes.setStockTimeName("0~6个月");
						getStockTimeListRes.setStockTimeNum(String.valueOf(m));
						stockTimeList.add(getStockTimeListRes);
					}else{
						getStockTimeListRes.setStockTimeName("0~6个月");
						getStockTimeListRes.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes);
					}
					if(n > 0){
						getStockTimeListRes2.setStockTimeName("6~12个月");
						getStockTimeListRes2.setStockTimeNum(String.valueOf(n));
						stockTimeList.add(getStockTimeListRes2);
					}else{
						getStockTimeListRes2.setStockTimeName("6~12个月");
						getStockTimeListRes2.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes2);
					}
					if(s > 0){
						getStockTimeListRes3.setStockTimeName("12~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes3.setStockTimeNum(String.valueOf(s));
						stockTimeList.add(getStockTimeListRes3);
					}else{
						getStockTimeListRes3.setStockTimeName("12~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes3.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes3);
					}
					if(d > 0){
						getStockTimeListRes4.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes4.setStockTimeNum(String.valueOf(d));
						stockTimeList.add(getStockTimeListRes4);
					}else{
						getStockTimeListRes4.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes4.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes4);
					}
					resDto.setStockTimeList(stockTimeList);
			}else if(Integer.parseInt(reqDto.getMonthlyLimit()) > 18 && Integer.parseInt(reqDto.getMonthlyLimit()) <= 24){
				CustomerCountDto customerCountDto = new CustomerCountDto();
				customerCountDto.setProjectCode(reqDto.getProjectCode());
				customerCountDto.setMerchantId(String.valueOf(reqDto.getMerchantId()));
				customerCountDto.setPropertyType(reqDto.getPropertyType());
				List<DealHouseCount> selectStockTimeList = projectMapper.selectStockTimeCount(customerCountDto);
				int m = 0,n=0,s=0,d=0,f=0;
					GetStockTimeListRes getStockTimeListRes = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes2 = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes3 = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes4 = new GetStockTimeListRes();
					GetStockTimeListRes getStockTimeListRes5 = new GetStockTimeListRes();
					for(DealHouseCount dealHouseCount : selectStockTimeList){
						if(Integer.parseInt(dealHouseCount.getStockTimeName()) >= 0*monthDay && Integer.parseInt(dealHouseCount.getStockTimeName()) <= 6*monthDay){
							m+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else if(Integer.parseInt(dealHouseCount.getStockTimeName()) > 6*monthDay && Integer.parseInt(dealHouseCount.getStockTimeName()) <= 12*monthDay){
							n+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else if(Integer.parseInt(dealHouseCount.getStockTimeName()) > 12*monthDay && Integer.parseInt(dealHouseCount.getStockTimeName()) <= 18*monthDay){
							s+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else if(Integer.parseInt(dealHouseCount.getStockTimeName()) > 18*monthDay && Integer.parseInt(reqDto.getMonthlyLimit())*monthDay >= Integer.parseInt(dealHouseCount.getStockTimeName())){
							d+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}else{
							f+=Integer.parseInt(dealHouseCount.getStockTimeNum());//存量时间数
						}
					}
					if(m > 0){
						getStockTimeListRes.setStockTimeName("0~6个月");
						getStockTimeListRes.setStockTimeNum(String.valueOf(m));
						stockTimeList.add(getStockTimeListRes);
					}else{
						getStockTimeListRes.setStockTimeName("0~6个月");
						getStockTimeListRes.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes);
					}
					if(n > 0){
						getStockTimeListRes2.setStockTimeName("6~12个月");
						getStockTimeListRes2.setStockTimeNum(String.valueOf(n));
						stockTimeList.add(getStockTimeListRes2);
					}else{
						getStockTimeListRes2.setStockTimeName("6~12个月");
						getStockTimeListRes2.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes2);
					}
					if(s > 0){
						getStockTimeListRes3.setStockTimeName("12~18个月");
						getStockTimeListRes3.setStockTimeNum(String.valueOf(s));
						stockTimeList.add(getStockTimeListRes3);
					}else{
						getStockTimeListRes3.setStockTimeName("12~18个月");
						getStockTimeListRes3.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes3);
					}
					if(d > 0){
						getStockTimeListRes4.setStockTimeName("18~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes4.setStockTimeNum(String.valueOf(d));
						stockTimeList.add(getStockTimeListRes4);
					}else{
						getStockTimeListRes4.setStockTimeName("18~"+Integer.parseInt(reqDto.getMonthlyLimit())+"个月");
						getStockTimeListRes4.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes4);
					}
					if(f > 0){
						getStockTimeListRes5.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes5.setStockTimeNum(String.valueOf(f));
						stockTimeList.add(getStockTimeListRes5);
					}else{
						getStockTimeListRes5.setStockTimeName(Integer.parseInt(reqDto.getMonthlyLimit())+"个月以上");
						getStockTimeListRes5.setStockTimeNum("0");
						stockTimeList.add(getStockTimeListRes5);
					}
					resDto.setStockTimeList(stockTimeList);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询存量时间分析失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getPaymentNotSignedList:(app查询已签约未回款分析接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @return 
     */
	@Override
	public GetPaymentNotSignedListResDto getPaymentNotSignedList(
			GetPaymentNotSignedListReqDto reqDto) {
		GetPaymentNotSignedListResDto resDto = new GetPaymentNotSignedListResDto();
		List<GetPaymentNotSignedListRes> paymentModeList = new ArrayList<GetPaymentNotSignedListRes>();//支付方式列表
		try{
			CustomerCountDto customerCountDto = new CustomerCountDto();
			customerCountDto.setMerchantId(String.valueOf(reqDto.getMerchantId()));
			customerCountDto.setProjectCode(reqDto.getProjectCode());
			List<DealHouseCount> selectPaymentNotSignedCount = projectMapper.selectPaymentNotSignedCount(customerCountDto);
			if(selectPaymentNotSignedCount.size() > 0){
				Double totalAmount = 0.0;
				for(DealHouseCount dealHouseCount : selectPaymentNotSignedCount){
					GetPaymentNotSignedListRes getPaymentNotSignedListRes = new GetPaymentNotSignedListRes();
					getPaymentNotSignedListRes.setPaymentModeName(PaymentMethodEnum.getByNo(dealHouseCount.getPaymentModeName()).getDes());//支付方式名称
					getPaymentNotSignedListRes.setPaymentModeAmount(df.format(Double.valueOf(dealHouseCount.getPaymentModeAmount())/10000));//支付方式金额
					totalAmount += Double.valueOf(dealHouseCount.getPaymentModeAmount());
					paymentModeList.add(getPaymentNotSignedListRes);
				}
				resDto.setTotalAmount(df.format(totalAmount/10000));//总额
				resDto.setPaymentModeList(paymentModeList);
			}else{
				resDto.setPaymentModeList(null);
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("查询已签约未回款分析失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	/**
     * getTimeConditionAnalysis:(app时间条件查询分析接口) - serviceImpl
     * 
     * @author 作者(ny)
     * @param version  app版本号
     * @param merchantId  商家Id
     * @param userId  用户编号
     * @param token 会话token
     * @param productCode 项目code
     * @param terminalCode  终端编码
     * @param gradesTimeType 成绩时间类型：1、今天（默认）；2、昨天；3、本周；4、上周；5、本月；6、上月；7、近三月；8、今年
     * @param gradesStartTime 成绩开始时间：格式yyyy-MM-dd
     * @param gradesEndTime 成绩结束时间：格式yyyy-MM-dd
     * @param monthlyType 月指标类型：1、本月；2、上月；3、近三月；4、近六月
     * @param monthlyStartTime 月指标开始时间：格式yyyy-MM
     * @param monthlyEndTime 月指标结束时间：格式yyyy-MM
     * @param yearTime 年指标时间：格式yyyy
     * 
     * @return 
     */
	@Override
	public GetTimeConditionAnalysisResDto getTimeConditionAnalysis(
			GetTimeConditionAnalysisReqDto reqDto) {
		GetTimeConditionAnalysisResDto resDto = new GetTimeConditionAnalysisResDto();
		DecimalFormat df_tca = new DecimalFormat("0.00");
		try{
			TimeConditionAnalysisReq timeConditionAnalysisReq = new TimeConditionAnalysisReq();
			BeanUtils.copyProperties(reqDto, timeConditionAnalysisReq);
			if(StringUtils.isNotBlank(reqDto.getGradesStartTime())){
				timeConditionAnalysisReq.setGradesStartTime(reqDto.getGradesStartTime() + " 00:00:00");
			}
			if(StringUtils.isNotBlank(reqDto.getGradesEndTime())){
				timeConditionAnalysisReq.setGradesEndTime(reqDto.getGradesEndTime() + " 23:59:59");
			}
			if(StringUtils.isNotBlank(reqDto.getMonthlyStartTime())){
				timeConditionAnalysisReq.setMonthlyStartTime(reqDto.getMonthlyStartTime()+ "-01");
			}
			if(StringUtils.isNotBlank(reqDto.getMonthlyEndTime())){
				timeConditionAnalysisReq.setMonthlyEndTime(reqDto.getMonthlyEndTime() + "-31");
			}
			TimeConditionAnalysisResAmount timeConditionAnalysisResAmount = projectMapper.selectTimeConditionAnalysis(timeConditionAnalysisReq);
			if(timeConditionAnalysisResAmount != null){
				//20180827_当前系统中的来电均为有效来电
				if(timeConditionAnalysisResAmount.getCallNum() != null){
					resDto.setCallNum(timeConditionAnalysisResAmount.getCallNum());//来电数量
					resDto.setCallValidNum(timeConditionAnalysisResAmount.getCallNum());//来电有效数量
				}else{
					resDto.setCallNum("0");//来电数量
					resDto.setCallValidNum("0");//来电有效数量
				}
				/*if(timeConditionAnalysisResAmount.getCallValidNum() != null){
					resDto.setCallValidNum(timeConditionAnalysisResAmount.getCallValidNum());//来电有效数量
				}else{
					resDto.setCallValidNum("0");//来电有效数量
				}*/
				if(timeConditionAnalysisResAmount.getVisitNum() != null){
					resDto.setVisitNum(timeConditionAnalysisResAmount.getVisitNum());//来访数量
				}else{
					resDto.setVisitNum("0");//来访数量
				}
				if(timeConditionAnalysisResAmount.getFreshCusVisitNum() != null){
					resDto.setFreshCusVisitNum(timeConditionAnalysisResAmount.getFreshCusVisitNum());//新客来访数量
				}else{
					resDto.setFreshCusVisitNum("0");//新客来访数量
				}
				//老客来访数量 = 来访数量 - 新客来访数量
				/*if(timeConditionAnalysisResAmount.getOldCusVisitNum() != null){
					resDto.setOldCusVisitNum(timeConditionAnalysisResAmount.getOldCusVisitNum());//老客来访数量
				}else{
					resDto.setOldCusVisitNum("0");//老客来访数量
				}*/
				int oldCusVisitNum = Integer.parseInt(timeConditionAnalysisResAmount.getVisitNum()) - Integer.parseInt(timeConditionAnalysisResAmount.getFreshCusVisitNum());
				resDto.setOldCusVisitNum(String.valueOf(oldCusVisitNum));//老客来访数量
				if(timeConditionAnalysisResAmount.getDepositNum() != null){
					resDto.setDepositNum(timeConditionAnalysisResAmount.getDepositNum());//认筹数量
				}else{
					resDto.setDepositNum("0");//认筹数量
				}
				if(timeConditionAnalysisResAmount.getSubscribeNum() != null){
					resDto.setSubscribeNum(timeConditionAnalysisResAmount.getSubscribeNum());//认购数量
				}else{
					resDto.setSubscribeNum("0");//认购数量
				}
				if(timeConditionAnalysisResAmount.getSubscribeAmount() != null){
					resDto.setSubscribeAmount(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getSubscribeAmount())/10000));//认购金额
				}else{
					resDto.setSubscribeAmount("0");//认购金额
				}
				if(timeConditionAnalysisResAmount.getSignedNum() != null){
					resDto.setSignedNum(timeConditionAnalysisResAmount.getSignedNum());//签约数量
				}else{
					resDto.setSignedNum("0");//签约数量
				}
				if(timeConditionAnalysisResAmount.getSignedAmount() != null){
					resDto.setSignedAmount(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getSignedAmount())/10000));//签约金额
				}else{
					resDto.setSignedAmount("0");//签约金额
				}
				if(timeConditionAnalysisResAmount.getPaymentAmount() != null){
					resDto.setPaymentAmount(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getPaymentAmount())/10000));//回款金额
				}else{
					resDto.setPaymentAmount("0");//回款金额
				}
				/**
				 * 年销售/回款指标、完成量
				 */
				//年销售完成量 / 指标
				if(timeConditionAnalysisResAmount.getYearSalesRate() != null && timeConditionAnalysisResAmount.getYearSalesTarget() != null){
					if("0.00".equals(timeConditionAnalysisResAmount.getYearSalesRate())){
						resDto.setYearSalesRate("0");
						resDto.setYearSalesTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget())/10000)+"/0");//年销售完成量 / 指标
					}else{
						Double yearSalesRate = Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget())/ Double.valueOf(timeConditionAnalysisResAmount.getYearSalesRate());
						resDto.setYearSalesRate(df_tca.format(yearSalesRate*100));//年销售指标完成率 = 年销售完成量/指标
						resDto.setYearSalesTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget())/10000)+"/"+df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearSalesRate())/10000));//年销售完成量 / 指标
					}
				}else{
					if(timeConditionAnalysisResAmount.getYearSalesTarget() != null){
						resDto.setYearSalesTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget())/10000)+"/0");//年销售完成量 / 指标
					}else if(timeConditionAnalysisResAmount.getYearSalesRate() != null){
						if("0.00".equals(timeConditionAnalysisResAmount.getYearSalesRate())){
							resDto.setYearSalesTarget("0");//年销售完成量 / 指标
						}else{
							resDto.setYearSalesTarget("0/"+df_tca.format(Double.valueOf(Double.valueOf(timeConditionAnalysisResAmount.getYearSalesRate())/10000)));//年销售完成量 / 指标
						}
					}else{
						resDto.setYearSalesTarget("0");//年销售完成量 / 指标
						resDto.setYearSalesRate("0");
					}
				}
				//年回款完成量 / 指标
				if(timeConditionAnalysisResAmount.getYearPaymentTarget() != null){
					Double yearPaymentRate_2 = 0.00;
					if("0.0".equals(timeConditionAnalysisResAmount.getYearPaymentRate()) || "0.00".equals(timeConditionAnalysisResAmount.getYearPaymentRate()) || timeConditionAnalysisResAmount.getYearPaymentRate() == null){
						resDto.setYearPaymentTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentTarget())/10000)+"/0");//年回款完成量 / 指标
						resDto.setYearPaymentRate("0");
					}else{
						resDto.setYearPaymentTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentTarget())/10000)+"/"+df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentRate())/10000));//年回款完成量 / 指标
						yearPaymentRate_2 = Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentTarget())/ Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentRate());
						resDto.setYearPaymentRate(df_tca.format(yearPaymentRate_2*100));//年回款指标完成率 = 年回款完成量/指标
					}
				}else{
					if("0.0".equals(timeConditionAnalysisResAmount.getYearPaymentRate()) || "0.00".equals(timeConditionAnalysisResAmount.getYearPaymentRate()) || timeConditionAnalysisResAmount.getYearPaymentRate() == null){
						resDto.setYearPaymentTarget("0");//年回款完成量 / 指标
					}else{
						resDto.setYearPaymentTarget("0/"+df_tca.format(Double.valueOf(Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentRate())/10000)));//年回款完成量 / 指标
					}
					resDto.setYearPaymentRate("0");
				}
				//综合完成量
				if(timeConditionAnalysisResAmount.getYearSalesRate() != null || timeConditionAnalysisResAmount.getYearPaymentRate() != null){
					Double salesTarget = 0.00;
					if(timeConditionAnalysisResAmount.getYearSalesTarget() != null && timeConditionAnalysisResAmount.getYearPaymentTarget() != null){
						salesTarget =Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget()) + Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentTarget()); //综合完成量
					}else{
						if(timeConditionAnalysisResAmount.getYearSalesTarget() == null && timeConditionAnalysisResAmount.getYearPaymentTarget() == null){
							salesTarget = 0.00;
						}else if(timeConditionAnalysisResAmount.getYearSalesTarget() == null){
							salesTarget =Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentTarget()); //综合完成量
						}else if(timeConditionAnalysisResAmount.getYearPaymentTarget() == null){
							salesTarget =Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget()); //综合完成量
						}
					}
					Double yearPayRate = 0.00;
					Double yearSalesRate = 0.00;
					if(timeConditionAnalysisResAmount.getYearPaymentRate() != null){
						yearPayRate = Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentRate());
					}
					if(timeConditionAnalysisResAmount.getYearSalesRate() != null){
						yearSalesRate = new BigDecimal(timeConditionAnalysisResAmount.getYearSalesRate()).doubleValue();
					}
					Double salesRate = yearSalesRate + yearPayRate; //综合指标
					if("0.0".equals(String.valueOf(salesRate))){
						if("0.00".equals(String.valueOf(salesTarget)) || "0.0".equals(String.valueOf(salesTarget))){
							resDto.setYearGeneralTarget("0");
							resDto.setYearGeneralRate("0");
						}else{
							resDto.setYearGeneralTarget(df_tca.format(salesTarget/10000) +"/0");
							resDto.setYearGeneralRate("0");
						}
					}else{
						if("0.0".equals(String.valueOf(salesRate)) && "0.0".equals(String.valueOf(salesTarget))){
							resDto.setYearGeneralTarget("0");
							resDto.setYearGeneralRate("0");
						}else if("0.0".equals(String.valueOf(salesRate))){
							resDto.setYearGeneralTarget(df_tca.format(salesTarget/10000) +"/0");
							resDto.setYearGeneralRate("0");
						}else if("0.0".equals(String.valueOf(salesTarget))){
							resDto.setYearGeneralTarget("0/"+df_tca.format(salesRate/10000));
							resDto.setYearGeneralRate("0");
						}else{
							resDto.setYearGeneralTarget(df_tca.format(salesTarget/10000) +"/"+df_tca.format(salesRate/10000));//年综合指标完成量 / 指标
							resDto.setYearGeneralRate(df_tca.format((salesTarget/salesRate)*100));//年综合指标完成率 = （销售指标完成量+回款指标完成量）/（销售指标+回款指标）
						}
					}
				}else{
					if(timeConditionAnalysisResAmount.getYearSalesTarget() != null && timeConditionAnalysisResAmount.getYearPaymentTarget() != null){
						Double salesTarget = 0.00;
						salesTarget =Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget()) + Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentTarget()); //综合完成量
						if("0.0".equals(String.valueOf(salesTarget))){
							resDto.setYearGeneralTarget("0");
							resDto.setYearGeneralRate("0");
						}else{
							resDto.setYearGeneralTarget(df_tca.format(salesTarget/10000) +"/0");
							resDto.setYearGeneralRate("0");
						}
					}else{
						if(timeConditionAnalysisResAmount.getYearSalesTarget() != null){
							resDto.setYearGeneralTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearSalesTarget())/10000)+"/0");
							resDto.setYearGeneralRate("0");
						}else if(timeConditionAnalysisResAmount.getYearPaymentTarget() != null){
							resDto.setYearGeneralTarget("0/"+df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getYearPaymentTarget())/10000));
							resDto.setYearGeneralRate("0");
						}else{
							resDto.setYearGeneralTarget("0");
							resDto.setYearGeneralRate("0");
						}
					}
				}
				
				/**
				 * 月销售/回款指标、完成量
				 */
				//月销售指标
				String monthSalesRate = getSalesTargetEntity(timeConditionAnalysisReq,"0");
				//月销售完成
				if(timeConditionAnalysisResAmount.getMonthlySalesTarget() != null){
					Double monthlyPaymentRate = 0.00;
					if("0.0".equals(monthSalesRate)){
						//monthSalesRate = "0.00";
						resDto.setMonthlySalesTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getMonthlySalesTarget())/10000)+"/0");//月销售完成量 / 指标
						resDto.setMonthlySalesRate("0");//月销售指标完成率 = 月销售完成量/指标
					}else{
						resDto.setMonthlySalesTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getMonthlySalesTarget())/10000)+"/"+df_tca.format(new BigDecimal(monthSalesRate).doubleValue()/10000));//月销售完成量 / 指标
						monthlyPaymentRate = Double.valueOf(timeConditionAnalysisResAmount.getMonthlySalesTarget())/Double.valueOf(monthSalesRate);
						resDto.setMonthlySalesRate(df_tca.format(monthlyPaymentRate*100));//月销售指标完成率 = 月销售完成量/指标
					}
				}else{
					if("0.0".equals(monthSalesRate)){
						monthSalesRate = "0";
						resDto.setMonthlySalesTarget(monthSalesRate);
					}else{
						resDto.setMonthlySalesTarget("0/"+df_tca.format(new BigDecimal(monthSalesRate).doubleValue()/10000));
					}
					resDto.setMonthlySalesRate("0");
				}
				//月回款指标
				String monthPaymentRate = getSalesTargetEntity(timeConditionAnalysisReq,"1");
				//月回款完成
				if(timeConditionAnalysisResAmount.getMonthlyPaymentTarget() != null){
					Double monthlyPaymentRate_2 = 0.00;
					if("0.0".equals(monthPaymentRate)){
						//monthPaymentRate = "0.00";
						resDto.setMonthlyPaymentTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getMonthlyPaymentTarget())/10000)+"/0");//月回款完成量 / 指标
						resDto.setMonthlyPaymentRate("0");//月回款指标完成率 = 月回款完成量/指标
					}else{
						resDto.setMonthlyPaymentTarget(df_tca.format(Double.valueOf(timeConditionAnalysisResAmount.getMonthlyPaymentTarget())/10000)+"/"+df_tca.format(Double.valueOf(monthPaymentRate)/10000));//月回款完成量 / 指标
						monthlyPaymentRate_2 = Double.valueOf(timeConditionAnalysisResAmount.getMonthlyPaymentTarget())/Double.valueOf(monthPaymentRate);
						resDto.setMonthlyPaymentRate(df_tca.format(monthlyPaymentRate_2*100));//月回款指标完成率 = 月回款完成量/指标
					}
				}else{
					if("0.0".equals(monthPaymentRate)){
						monthPaymentRate = "0";
						resDto.setMonthlyPaymentTarget(monthPaymentRate);
					}else{
						resDto.setMonthlyPaymentTarget("0/"+df_tca.format(Double.valueOf(monthPaymentRate)/10000));
					}
					resDto.setMonthlyPaymentRate("0");
				}
				//月综合指标、完成量
				if(monthPaymentRate != null || monthSalesRate != null){
					Double salesMonthsTarget = 0.00;
					if(timeConditionAnalysisResAmount.getMonthlySalesTarget() != null && timeConditionAnalysisResAmount.getMonthlyPaymentTarget() != null){
						salesMonthsTarget =Double.valueOf(timeConditionAnalysisResAmount.getMonthlySalesTarget()) + Double.valueOf(timeConditionAnalysisResAmount.getMonthlyPaymentTarget()); //综合完成量
					}else{
						if(timeConditionAnalysisResAmount.getMonthlySalesTarget() == null && timeConditionAnalysisResAmount.getMonthlyPaymentTarget() == null){
							salesMonthsTarget = 0.00; //综合完成量
						}else if(timeConditionAnalysisResAmount.getMonthlySalesTarget() == null){
							salesMonthsTarget =Double.valueOf(timeConditionAnalysisResAmount.getMonthlyPaymentTarget()); //综合完成量
						}else if(timeConditionAnalysisResAmount.getMonthlyPaymentTarget() == null){
							salesMonthsTarget =Double.valueOf(timeConditionAnalysisResAmount.getMonthlySalesTarget()); //综合完成量
						}
					}
					Double monthsPayRate = 0.00;
					Double monthsSalesRate = 0.00;
					if(monthPaymentRate != null){
						monthsPayRate = Double.valueOf(monthPaymentRate);
					}
					if(monthSalesRate != null){
						monthsSalesRate = new BigDecimal(monthSalesRate).doubleValue();
					}
					Double salesMonthsRate = monthsPayRate + monthsSalesRate; //综合指标
					if("0.0".equals(String.valueOf(salesMonthsRate))){
						if("0.00".equals(String.valueOf(salesMonthsTarget)) || "0.0".equals(String.valueOf(salesMonthsTarget))){
							resDto.setMonthlyGeneralTarget("0");
							resDto.setMonthlyGeneralRate("0");
						}else{
							resDto.setMonthlyGeneralTarget(df_tca.format(salesMonthsTarget/10000)+"/0");
							resDto.setMonthlyGeneralRate("0");
						}
					}else{
						if("0.0".equals(String.valueOf(salesMonthsRate)) && "0.0".equals(String.valueOf(salesMonthsTarget))){
							resDto.setMonthlyGeneralTarget("0");
							resDto.setMonthlyGeneralRate("0");
						}else if("0.0".equals(String.valueOf(salesMonthsRate))){
							resDto.setMonthlyGeneralTarget(df_tca.format(salesMonthsTarget/10000)+"/0");
							resDto.setMonthlyGeneralRate("0");
						}else if("0.0".equals(String.valueOf(salesMonthsTarget))){
							resDto.setMonthlyGeneralTarget("0/"+df_tca.format(salesMonthsRate/10000));
							resDto.setMonthlyGeneralRate("0");
						}else{
							resDto.setMonthlyGeneralTarget(df_tca.format(salesMonthsTarget/10000) +"/"+df_tca.format(salesMonthsRate/10000));//年综合指标完成量 / 指标
							resDto.setMonthlyGeneralRate(df_tca.format((salesMonthsTarget/salesMonthsRate)*100));//年综合指标完成率 = （销售指标完成量+回款指标完成量）/（销售指标+回款指标）
						}
					}
				}else{
					resDto.setMonthlyGeneralTarget("0");
					resDto.setMonthlyGeneralRate("0");
				}
				
			}
		}catch(Exception e){
			e.printStackTrace();
			resDto.setErrorCode("0000");
			resDto.setErrorMsg("时间条件查询分析失败");
			resDto.setResult(ResultEnum.FAILURE.getNo());
			return resDto;
		}
		resDto.setResult(ResultEnum.SUCCESS.getNo());
		return resDto;
	}

	@Override
	public String getSalesTargetEntity(TimeConditionAnalysisReq timeConditionAnalysisReq, String flag) {
		Double monthlySalesAmount = 0.00;
		List<SalesTargetPmo> salesTargetPmoList = null;
		if(timeConditionAnalysisReq.getMonthlyType() != null){
			//月销售指标完成率
			SimpleDateFormat sdf_ym = new SimpleDateFormat("yyyy-MM");//格式化为年月
			//SimpleDateFormat sdf_mm = new SimpleDateFormat("MM");
			ArrayList<String> result = new ArrayList<String>();
			Calendar ca = Calendar.getInstance();
			Date date = new Date();
			if("1".equals(timeConditionAnalysisReq.getMonthlyType())){//本月
				int year = ca.get(Calendar.YEAR);
				int month = ca.get(Calendar.MONTH)+1;
				//String s = String.valueOf(year)+"-"+String.valueOf(sdf_mm.format(month));
				String s = String.valueOf(year)+"-0"+String.valueOf(month);
				result.add(s);
			}else if("2".equals(timeConditionAnalysisReq.getMonthlyType())){///上月
		        ca.setTime(date);
		        ca.add(Calendar.MONTH, -1);
		        result.add(sdf_ym.format(ca.getTime()));
			}else if("3".equals(timeConditionAnalysisReq.getMonthlyType())){//近三月
				int year = ca.get(Calendar.YEAR);
				int month = ca.get(Calendar.MONTH)+1;
				//String s = String.valueOf(year)+"-"+String.valueOf(sdf_mm.format(month));
				String s = String.valueOf(year)+"-0"+String.valueOf(month);
				result.add(s);//本月
				
				ca.setTime(date);
		        ca.add(Calendar.MONTH, -1);
		        result.add(sdf_ym.format(ca.getTime()));//上一月
				
		        ca.setTime(date);
		        ca.add(Calendar.MONTH, -2);
		        result.add(sdf_ym.format(ca.getTime()));//上两月
			}else if("4".equals(timeConditionAnalysisReq.getMonthlyType())){//近六月
				int year = ca.get(Calendar.YEAR);
				int month = ca.get(Calendar.MONTH)+1;
				//String s = String.valueOf(year)+"-"+String.valueOf(sdf_mm.format(month));
				String s = String.valueOf(year)+"-0"+String.valueOf(month);
				result.add(s);//本月
				
				ca.setTime(date);
		        ca.add(Calendar.MONTH, -1);
		        result.add(sdf_ym.format(ca.getTime()));//上一月
				
		        ca.setTime(date);
		        ca.add(Calendar.MONTH, -2);
		        result.add(sdf_ym.format(ca.getTime()));//上两月
		        
		        ca.setTime(date);
		        ca.add(Calendar.MONTH, -3);
		        result.add(sdf_ym.format(ca.getTime()));//上三月
		        
				ca.setTime(date);
				ca.add(Calendar.MONTH, -4);
		        result.add(sdf_ym.format(ca.getTime()));//上四月
				
		        ca.setTime(date);
		        ca.add(Calendar.MONTH, -5);
		        result.add(sdf_ym.format(ca.getTime()));//上五月
			}
			for(int i=0;i<result.size();i++){
				SalesTargetPmoDto salesTargetPmoDto = new SalesTargetPmoDto();
				salesTargetPmoDto.setMerchantId(timeConditionAnalysisReq.getMerchantId());
				salesTargetPmoDto.setProjectCode(timeConditionAnalysisReq.getProjectCode());
				salesTargetPmoDto.setQuotaType(flag);
				salesTargetPmoDto.setSalesYear(result.get(i).substring(0, 4));
				salesTargetPmoList = salesTargetPmoService.querySalesTargetPmoEntity(salesTargetPmoDto);
				if(salesTargetPmoList != null){
					for(SalesTargetPmo salesTargetPmo : salesTargetPmoList){
						if("01".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getJanuaryValue()==null?0:salesTargetPmo.getJanuaryValue()));
						}else if("02".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getFebruaryValue()==null?0:salesTargetPmo.getFebruaryValue()));
						}else if("03".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getMarchValue()==null?0:salesTargetPmo.getMarchValue()));
						}else if("04".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getAprilValue()==null?0:salesTargetPmo.getAprilValue()));
						}else if("05".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getMayValue()==null?0:salesTargetPmo.getMayValue()));
						}else if("06".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getJuneValue()==null?0:salesTargetPmo.getJuneValue()));
						}else if("07".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getJulyValue()==null?0:salesTargetPmo.getJulyValue()));
						}else if("08".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getAugustValue()==null?0:salesTargetPmo.getAugustValue()));
						}else if("09".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getSeptemberValue()==null?0:salesTargetPmo.getSeptemberValue()));
						}else if("10".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getOctoberValue()==null?0:salesTargetPmo.getOctoberValue()));
						}else if("11".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getNovemberValue()==null?0:salesTargetPmo.getNovemberValue()));
						}else if("12".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getDecemberValue()==null?0:salesTargetPmo.getDecemberValue()));
						}
					}
				}
			}
		}else if(timeConditionAnalysisReq.getMonthlyStartTime() != null && timeConditionAnalysisReq.getMonthlyEndTime() != null){
			ArrayList<String> result = new ArrayList<String>();
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月
			Calendar min = Calendar.getInstance();
			Calendar max = Calendar.getInstance();
			try {
				min.setTime(sdf.parse(timeConditionAnalysisReq.getMonthlyStartTime()));
				max.setTime(sdf.parse(timeConditionAnalysisReq.getMonthlyEndTime()));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1);
			max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2);
			Calendar curr = min;
			while (curr.before(max)) {
			 result.add(sdf.format(curr.getTime()));
			 curr.add(Calendar.MONTH, 1);
			}
			for(int i=0;i<result.size();i++){
				SalesTargetPmoDto salesTargetPmoDto = new SalesTargetPmoDto();
				salesTargetPmoDto.setMerchantId(timeConditionAnalysisReq.getMerchantId());
				salesTargetPmoDto.setProjectCode(timeConditionAnalysisReq.getProjectCode());
				salesTargetPmoDto.setQuotaType(flag);
				salesTargetPmoDto.setSalesYear(result.get(i).substring(0, 4));
				salesTargetPmoList = salesTargetPmoService.querySalesTargetPmoEntity(salesTargetPmoDto);
				if(salesTargetPmoList != null){
					for(SalesTargetPmo salesTargetPmo : salesTargetPmoList){
						if("01".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getJanuaryValue()));
						}else if("02".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getFebruaryValue()));
						}else if("03".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getMarchValue()));
						}else if("04".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getAprilValue()));
						}else if("05".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getMayValue()));
						}else if("06".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getJuneValue()));
						}else if("07".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getJulyValue()));
						}else if("08".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getAugustValue()));
						}else if("09".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getSeptemberValue()));
						}else if("10".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getOctoberValue()));
						}else if("11".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getNovemberValue()));
						}else if("12".equals(result.get(i).substring(5, 7))){
							monthlySalesAmount += Double.valueOf(String.valueOf(salesTargetPmo.getDecemberValue()));
						}
					}
				}
			}
		}
		return String.valueOf(monthlySalesAmount);
	}
	
	public User getUser(){
		UserDto userDto = new UserDto();
		userDto.setIsAdmin("1");
		userDto.setMerchantId(Long.valueOf("1"));
		List<User> userList = userService.selectListByDto(userDto);
		User user=userList.get(0);
		return user;
	}
	
	public void saveOrUpdate(List<SaleReturnPmo> saleList,User user,SaleReturnPmoDto entity){
		if(saleList==null||saleList.size()<=0){
			entity.setSaleActual("0");
			entity.setCreateUserId(user.getId());
			saleReturnPmoService.create(entity);
		}else{
			entity.setId(saleList.get(0).getId());
			saleReturnPmoService.saveOrUpdate(entity);
		}
	}
	
	public SaleReturnPmoDto getSaleReturnEntity(SaleReturnEnum saleReturnEnum,String objectType,Long objectId,String month){
		SaleReturnPmoDto entity = new SaleReturnPmoDto();
		entity.setSaleReturn(saleReturnEnum.getNo());
		entity.setObjectType(objectType);
		entity.setObjectId(objectId);
		
		if(!com.alibaba.druid.util.StringUtils.isEmpty(month)){
			String saleYear = month.substring(0, 4);
			String saleMonth = month.substring(4, 6);
			entity.setSaleMonth(saleMonth);
			entity.setSaleYear(saleYear);
		}
		entity.setDelFlag(DelFlagEnum.UNDEL.getNo());
		return entity;
	}
	
	public void createOrEditSaleReturn(List<PlanneBack> list,List<PlannedSales> salesList,SaleReturnEnum saleReturnEnum,String objectType,Long objectId){
		User user = getUser();
		if(list!=null){
			for (PlanneBack planne : list) {
				SaleReturnPmoDto entity = getSaleReturnEntity(saleReturnEnum, objectType, objectId, planne.getMonth());
				List<SaleReturnPmo> saleList = saleReturnPmoService.selectListByDto(entity);
				/*
				 * 初始化时,计算实际销售、回款及计算差额
				//获取项目实际销售及实际收款,并计算差额
				if(objectType.equals(ObjectTypeEnum.PROJECT.getNo())){
					ProjectPmoDto ppDto = new ProjectPmoDto();
					ppDto.setProjectId(objectId);
					ProjectPmo pp = projectPmoService.selectByDto(ppDto);
					String pmoProjectCode = "";
					if(null != pp){
						pmoProjectCode = pp.getPmoProjectCode();
					}
					Response<LevelDynamiSalesData> ldsdRes = projectServiceFacade.quereyLevelDynamiSalesData(pmoProjectCode, planne.getMonth());
					if(ldsdRes.isSuccess()){
						LevelDynamiSalesData ldsd = ldsdRes.getEntity();
						DynamiSalesData dsd = ldsd.getData();
						//计划金额
						double plan = planne.getPlanneBackAmount()==null?(new BigDecimal(0).doubleValue()):(planne.getPlanneBackAmount().doubleValue());
						//实际销售额
						double actualSalesAmount = dsd.getActualSalesAmount()==null?0:dsd.getActualSalesAmount();
						//实际回款额
						double actualBackAmount = dsd.getActualBackAmount()==null?0:dsd.getActualBackAmount();
						//差额
						double saleDiff = 0;
						//销售类型
						if(SaleReturnEnum.SALE.getNo().equals(saleReturnEnum.getNo())){
							entity.setSaleActual(String.valueOf(actualSalesAmount));
							saleDiff = plan - actualSalesAmount;
							entity.setSaleDiff(String.valueOf(saleDiff));
						}else if(SaleReturnEnum.RETURN.getNo().equals(saleReturnEnum.getNo())){
							entity.setSaleActual(String.valueOf(actualBackAmount));
							saleDiff = plan - actualBackAmount;
							entity.setSaleDiff(String.valueOf(saleDiff));
						}
					}
				}else if(objectType.equals(ObjectTypeEnum.PREMISES.getNo())){
					//根据组团ID,获取到项目ID
					ProjectPremises proPre = projectPremisesService.selectById(objectId);
					String pmoProjectCode = "";
					if(null != proPre){
						ProjectPmoDto ppDto = new ProjectPmoDto();
						ppDto.setProjectId(proPre.getProjectId());
						ProjectPmo pp = projectPmoService.selectByDto(ppDto);
						if(null != pp){
							//项目 pmo 编号
							pmoProjectCode = pp.getPmoProjectCode();
						}
					}
					Response<LevelDynamiSalesData> ldsdRes = projectServiceFacade.quereyLevelDynamiSalesData(pmoProjectCode, planne.getMonth());
					if(ldsdRes.isSuccess()){
						//组团销售、回款明细数据
						List<LevelDynamiSalesData> ldsdList = ldsdRes.getEntity().getDynamiSalesDatas();
						if(null != ldsdList){
							for(LevelDynamiSalesData ldsd: ldsdList){
								//销售、回款详情
								DynamiSalesData dsd = ldsd.getData();
								//匹配组团月份
								if(planne.getMonth().equals(dsd.getMonth())){
									//计划金额
									double plan = planne.getPlanneBackAmount()==null?(new BigDecimal(0).doubleValue()):(planne.getPlanneBackAmount().doubleValue());
									//实际销售额
									double actualSalesAmount = dsd.getActualSalesAmount()==null?0:dsd.getActualSalesAmount();
									//实际回款额
									double actualBackAmount = dsd.getActualBackAmount()==null?0:dsd.getActualBackAmount();
									//差额
									double saleDiff = 0;
									//销售类型
									if(SaleReturnEnum.SALE.getNo().equals(saleReturnEnum.getNo())){
										entity.setSaleActual(String.valueOf(actualSalesAmount));
										saleDiff = plan - actualSalesAmount;
										entity.setSaleDiff(String.valueOf(saleDiff));
									}else if(SaleReturnEnum.RETURN.getNo().equals(saleReturnEnum.getNo())){
										entity.setSaleActual(String.valueOf(actualBackAmount));
										saleDiff = plan - actualBackAmount;
										entity.setSaleDiff(String.valueOf(saleDiff));
									}
								}
							}
						}
					}
				}
				*/
				entity.setSalePlan(planne.getPlanneBackAmount()+"");
				saveOrUpdate(saleList, user, entity);
			}
		}else{
			for (PlannedSales sales:salesList) {
				SaleReturnPmoDto entity = getSaleReturnEntity(saleReturnEnum, objectType, objectId, sales.getMonth());
				List<SaleReturnPmo> saleList = saleReturnPmoService.selectListByDto(entity);
				entity.setSalePlan(sales.getPlanneSaleAmount()+"");
				saveOrUpdate(saleList, user, entity);
			}
		}
		
	}
	
	/**
     * projectsPmo:(项目创建与编辑接口（绿城扩展PMO）) - serviceImpl
     * 
     * @author 作者(ny)
     * @param reqDto
     * @return 
     */
	@Override
	public ProjectsPmoResDto projectsPmo(ProjectsPmoReqDto reqDto) {
		ProjectsPmoResDto resDto = new ProjectsPmoResDto();
		if(StringUtils.isBlank(reqDto.getProjectCode())){
			resDto.setCode("10000004");
			resDto.setDesc("项目编码为空");
			return resDto;
		}
		
		
		SimpleDateFormat sdf_ymd = new SimpleDateFormat("yyyyMMdd");
		PmoLogDto pmoLogDto = new PmoLogDto();
		User user=null;
		try {
			
			/**
			 * 用户信息
			 */
			UserDto userDto = new UserDto();
			userDto.setIsAdmin("1");
			userDto.setMerchantId(Long.valueOf("1"));
			List<User> userList = userService.selectListByDto(userDto);
			user=userList.get(0);
			/**
			 * 1、projectCode在pro_tm_project_pmo中查询为空：作新增项目操作
			 * 2、projectCode在pro_tm_project_pmo中查询不为空：作修改项目操作
			 */
			ProjectPmoDto projectPmoDto = new ProjectPmoDto();
			projectPmoDto.setPmoProjectCode(reqDto.getProjectCode());
			ProjectPmo projectPmo = projectPmoService.selectByDto(projectPmoDto);
//			if(!reqDto.isAdd() && null==projectPmo){
//				//更新操作，如果项目code不存在，则不能更新
//				resDto.setCode("10000010");
//				resDto.setDesc("项目编码："+reqDto.getProjectCode()+"不存在");
//				return resDto;
//			}
			if(projectPmo != null){
				if(reqDto.isAdd()){
					resDto.setCode("10000005");
					resDto.setDesc("项目编码："+reqDto.getProjectCode()+"已存在");
					return resDto;
				}
				/**
				 * 更新项目pmo表
				 */
				//开发周期,格式yyyymmdd-yyyymmdd
				if(StringUtils.isNotEmpty(reqDto.getData().getDevlopCycle())){
					projectPmoDto.setDevlopCycle(reqDto.getData().getDevlopCycle());
				}
				//项目案名
				if(StringUtils.isNotEmpty(reqDto.getData().getProjecCaseName())){
					projectPmoDto.setProjecCaseName(reqDto.getData().getProjecCaseName());
				}
				//计划销售额：单位：万元
				List<PlannedSales> psList=reqDto.getData().getPlanneSalesAmount();
				if(null!=psList && psList.size()>0){
					createOrEditSaleReturn(null,psList,SaleReturnEnum.SALE, ObjectTypeEnum.PROJECT.getNo(), projectPmo.getProjectId());
					String planneSalesAmountJson=JSON.toJSONString(psList);
					//需要实现
					projectPmoDto.setPlanneSalesAmountJson(planneSalesAmountJson);
					
				}
				//计划回款额：单位：万元
				List<PlanneBack> pbList=reqDto.getData().getPlanneBackAmount();
				if(null!=pbList && pbList.size()>0){
					createOrEditSaleReturn(pbList,null,SaleReturnEnum.RETURN, ObjectTypeEnum.PROJECT.getNo(), projectPmo.getProjectId());
					//需要实现
					String planneBackAmountJson=JSON.toJSONString(pbList);
					projectPmoDto.setPlanneBackAmountJson(planneBackAmountJson);
				}
				String msg = "";
				try {
					//项目开始日期，格式：yyyymmdd
					
					if(StringUtils.isNotEmpty(reqDto.getData().getStartDate())){
						msg = "开工日期-实际";
						projectPmoDto.setStartDate(sdf_ymd.parse(reqDto.getData().getStartDate()));
					}
					//项目截止日期，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getEndDate())){
						msg = "项目截止日期";
						projectPmoDto.setEndDate(sdf_ymd.parse(reqDto.getData().getEndDate()));
					}
					//开工日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualStartOperatDate())){
						msg = "开工日期-实际";
						projectPmoDto.setActualStartOperatDate(sdf_ymd.parse(reqDto.getData().getActualStartOperatDate()));
					}
					//交付日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualDueDate())){
						msg = "交付日期-实际";
						projectPmoDto.setActualDueDate(sdf_ymd.parse(reqDto.getData().getActualDueDate()));
					}
					//首开日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneFirstDayStartOperat())){
						msg = "首开日期-计划";
						projectPmoDto.setPlanneFirstDayStartOperat(sdf_ymd.parse(reqDto.getData().getPlanneFirstDayStartOperat()));
					}
					//首开日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualFirstDayStartOperat())){
						msg = "首开日期-实际";
						projectPmoDto.setActualFirstDayStartOperat(sdf_ymd.parse(reqDto.getData().getActualFirstDayStartOperat()));
					}
					//竣工日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneCompleDate())){
						msg = "竣工日期-计划";
						projectPmoDto.setPlanneCompleDate(sdf_ymd.parse(reqDto.getData().getPlanneCompleDate()));
					}
					//竣工日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualCompleDate())){
						msg = "竣工日期-实际";
						projectPmoDto.setActualCompleDate(sdf_ymd.parse(reqDto.getData().getActualCompleDate()));
					}
				} catch (Exception e) {
					resDto.setCode("10000006");
					resDto.setDesc("日期转换错误:"+msg);
					return resDto;
				}
				//监理单位
				if(StringUtils.isNotEmpty(reqDto.getData().getSupervUnit())){
					projectPmoDto.setSupervUnit(reqDto.getData().getSupervUnit());
				}
				//总包单位
				if(StringUtils.isNotEmpty(reqDto.getData().getContraUnit())){
					projectPmoDto.setContraUnit(reqDto.getData().getContraUnit());
				}
				//景观单位
				if(StringUtils.isNotEmpty(reqDto.getData().getSightUnit())){
					projectPmoDto.setSightUnit(reqDto.getData().getSightUnit());
				}
				//精装修单位
				if(StringUtils.isNotEmpty(reqDto.getData().getDecoraUnit())){
					projectPmoDto.setDecoraUnit(reqDto.getData().getDecoraUnit());
				}
				//设计单位
				if(StringUtils.isNotEmpty(reqDto.getData().getDesignUnit())){
					projectPmoDto.setDesignUnit(reqDto.getData().getDesignUnit());
				}
				//建设类型
				if(StringUtils.isNotEmpty(reqDto.getData().getConstrType())){
					projectPmoDto.setConstrType(reqDto.getData().getConstrType());
				}
				if(StringUtils.isNotEmpty(reqDto.getData().getProjectName())){
					projectPmoDto.setPmoProjectName(reqDto.getData().getProjectName());
				}
				projectPmoDto.setId(projectPmo.getId());
				projectPmoService.update(projectPmoDto);
				
				/**
				 * 更新项目主表
				 */
				ProjectDto projectDto = new ProjectDto();
				
				//物业类型对应M2产品类型
				String properType=reqDto.getData().getProperType();
				if(StringUtils.isNotEmpty(properType)){
					String[] properTypes=properType.split(",");
					StringBuffer projectTypes=new StringBuffer("");
					for(int i=0;i<properTypes.length;i++){
						ProjectTypeEnum pyEnum=ProjectTypeEnum.getByDescription(properTypes[i]);
						if(null==pyEnum)continue;
						if(StringUtils.isNotBlank(projectTypes.toString())){
							projectTypes.append(",");
						}
						projectTypes.append(pyEnum.getNo());
					}
					projectDto.setProjectType(projectTypes.toString());
					
				}
				//项目名称
				if(StringUtils.isNotEmpty(reqDto.getData().getProjectName())){
					projectDto.setProjectName(reqDto.getData().getProjectName());
				}
				//产权年限，单位：年
				if(StringUtils.isNotEmpty(String.valueOf(reqDto.getData().getProperPeriod()))){
					projectDto.setPropertyYear(reqDto.getData().getProperPeriod());
				}
				//规证分期数，单位：期
				if(StringUtils.isNotEmpty(String.valueOf(reqDto.getData().getStageNumber()))){
					projectDto.setStagesNum(reqDto.getData().getStageNumber());
				}
				//所在城市
				CityInfo cityInfo=reqDto.getData().getCity();
				if(null!=cityInfo){
					String province= cityInfo.getProvince();
					String city= cityInfo.getCity();
					String zone= cityInfo.getZone();
					if(StringUtils.isNotBlank(province)){
						AreaDto areaDto = new AreaDto();
						areaDto.setAreaName(province);
						Area area = areaService.selectByDto(areaDto);
						if(null!=area){
							projectDto.setProvinceId(area.getId());
						}
					}
					
					if(StringUtils.isNotBlank(city)){
						AreaDto areaDto = new AreaDto();
						areaDto.setAreaName(city);
						Area area = areaService.selectByDto(areaDto);
						if(null!=area){
							projectDto.setCityId(area.getId());
						}
					}
					
					if(StringUtils.isNotBlank(zone)){
						AreaDto areaDto = new AreaDto();
						areaDto.setAreaName(zone);
						Area area = areaService.selectByDto(areaDto);
						if(null!=area){
							projectDto.setAreaId(area.getId());
						}
					}
					
				}
				//楼盘地址
				if(StringUtils.isNotEmpty(reqDto.getData().getBuildiAddres())){
					projectDto.setPremisesAddress(reqDto.getData().getBuildiAddres());
				}
				//项目配套
				if(StringUtils.isNotEmpty(reqDto.getData().getProjecSuppor())){
					projectDto.setProjectRequirement(reqDto.getData().getProjecSuppor());
				}
				//交通情况
				if(StringUtils.isNotEmpty(reqDto.getData().getTraffiStatus())){
					projectDto.setTrafficCase(reqDto.getData().getTraffiStatus());
				}
				//开发商名称
				if(StringUtils.isNotEmpty(reqDto.getData().getDevelopName())){
					projectDto.setDeveloperName(reqDto.getData().getDevelopName());
				}
				//开发商地址
				if(StringUtils.isNotEmpty(reqDto.getData().getDevelopAddres())){
					projectDto.setDeveloperAddress(reqDto.getData().getDevelopAddres());
				}
				String timeMsg = "";
				try {
					//开工日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneStartOperatDate())){
						timeMsg="开工日期-计划";
						projectDto.setStartTime(sdf_ymd.parse(reqDto.getData().getPlanneStartOperatDate()));
					}
					//交付日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneDueDate())){
						timeMsg="交付日期-计划";
						projectDto.setDeliveryDate(sdf_ymd.parse(reqDto.getData().getPlanneDueDate()));
					}
				} catch (Exception e) {
					resDto.setCode("10000006");
					resDto.setDesc("日期转换错误:"+timeMsg);
					return resDto;
				}
				
				projectDto.setId(projectPmo.getProjectId());
				Project project = projectService.selectById(projectPmo.getProjectId());
				if(null != project){
					projectDto.setProjectCode(project.getProjectCode());
					projectService.update(projectDto);
				}

				/**
				 * 更新项目Info表
				 */
				ProjectInfoDto projectInfoDto = new ProjectInfoDto();
				//物业类型
	/*			if(StringUtils.isNotEmpty(reqDto.getData().getProperType())){
					if(reqDto.getData().getProperType().equals(TenementTypeEnum.HOUSE.getDes()) || reqDto.getData().getProperType().equals(TenementTypeEnum.NON_HOUSE.getDes())){
						projectInfoDto.setTenementType(TenementTypeEnum.getByDescription(reqDto.getData().getProperType()).getNo());
					}
				}*/
				//四至边界
				if(StringUtils.isNotEmpty(reqDto.getData().getFourBorder())){
					projectInfoDto.setFourBorder(reqDto.getData().getFourBorder());
				}
				//邮政编码
				if(StringUtils.isNotEmpty(reqDto.getData().getZipCode())){
					projectInfoDto.setZipCode(reqDto.getData().getZipCode());
				}
				ProjectInfoDto proInfoDto_entity = new ProjectInfoDto();
				proInfoDto_entity.setProjectId(projectPmo.getProjectId());
				ProjectInfo projectInfo = projectInfoService.selectByDto(proInfoDto_entity);
				projectInfoDto.setId(projectInfo.getId());
				projectInfoService.update(projectInfoDto);
				
				/**
				 * 更新项目图片表
				 * 图片入参：存在多个以英文逗号隔开
				 */
				//项目LOGO URL，存在多个以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getLogoUrl())){
					saveProjectImg(user, projectDto, reqDto.getData().getLogoUrl(), "1");
				}
				//总平面图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getMasterDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getMasterDiagra(), "2");
				}
				//周边配套图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getAroundSupporDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getAroundSupporDiagra(), "3");
				}
				//交通图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getTraffiDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getTraffiDiagra(), "4");
				}
				//实景图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getRealDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getRealDiagra(), "5");
				}
				//样板图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getTemplateDrawing())){
					saveProjectImg(user, projectDto, reqDto.getData().getTemplateDrawing(), "6");
				}
				//效果图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getImpreDrawing())){
					saveProjectImg(user, projectDto, reqDto.getData().getImpreDrawing(), "7");
				}
				
				/**
				 * 项目组团信息
				 */
				if(null!=reqDto.getProjectDatas() && reqDto.getProjectDatas().size() > 0){
					for(int i=0;i<reqDto.getProjectDatas().size();i++){
						if(StringUtils.isBlank(reqDto.getProjectDatas().get(i).getProjectCode())){
							resDto.setCode("10000007");
							resDto.setDesc("组团编码为空");
							return resDto;
						}
						ProjectPremisesPmoDto projectPremisesPmoDto = new ProjectPremisesPmoDto();
						projectPremisesPmoDto.setPmoPremisesCode(reqDto.getProjectDatas().get(i).getProjectCode());
						ProjectPremisesPmo projectPremisesPmo = projectPremisesPmoService.selectByDto(projectPremisesPmoDto);
						//开发周期、格式为yyyymmdd-yyyymmdd
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDevlopCycle())){
							projectPremisesPmoDto.setDevlopCycle(reqDto.getProjectDatas().get(i).getData().getDevlopCycle());
						}
						//项目案名
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProjecCaseName())){
							projectPremisesPmoDto.setProjectCaseName(reqDto.getProjectDatas().get(i).getData().getProjecCaseName());
						}
					    //计划销售额：单位：万元
		                List<PlannedSales> psList1=reqDto.getData().getPlanneSalesAmount();
		                if(null!=psList1 && psList1.size()>0){
		                    //需要实现
		                	String planneSalesAmountJson=JSON.toJSONString(psList1);
							//需要实现
		                	projectPremisesPmoDto.setPlanneSalesAmountJson(planneSalesAmountJson);

		                }
		                //计划回款额：单位：万元
		                List<PlanneBack> pbList1=reqDto.getData().getPlanneBackAmount();
		                if(null!=pbList1 && pbList1.size()>0){
		                    //需要实现
							String planneBackAmountJson=JSON.toJSONString(pbList1);
							projectPremisesPmoDto.setPlanneBackAmountJson(planneBackAmountJson);
		                }
		                String t_msg = "";
						try {
							//项目开始日期，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getStartDate())){
								t_msg = "项目开始日期";
								projectPremisesPmoDto.setStartDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getStartDate()));
							}
							//项目截止日期，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getEndDate())){
								t_msg = "项目截止日期";
								projectPremisesPmoDto.setEndDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getEndDate()));
							}
							//开工日期-实际，格式：yyyymmdd
							
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualStartOperatDate())){
								t_msg = "开工日期-实际";
								projectPremisesPmoDto.setActualStartOperatDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualStartOperatDate()));
							}
							//交付日期-实际，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualDueDate())){
								t_msg = "交付日期-实际";
								projectPremisesPmoDto.setActualDueDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualDueDate()));
							}
							//首开日期-计划，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneFirstDayStartOperat())){
								t_msg = "首开日期-计划";
								projectPremisesPmoDto.setPlanneFirstDayStartOperat(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneFirstDayStartOperat()));
							}
							//首开日期-实际，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualFirstDayStartOperat())){
								t_msg = "首开日期-实际";
								projectPremisesPmoDto.setActualFirstDayStartOperat(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualFirstDayStartOperat()));
							}
							//竣工日期-计划，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneCompleDate())){
								t_msg = "竣工日期-计划";
								projectPremisesPmoDto.setPlanneCompleDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneCompleDate()));
							}
							//竣工日期-实际，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualCompleDate())){
								t_msg = "竣工日期-实际";
								projectPremisesPmoDto.setActualCompleDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualCompleDate()));
							}
							
							//开工日期-计划，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneStartOperatDate())){
								t_msg = "开工日期-计划";
								projectPremisesPmoDto.setPlanneStartOperatDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneStartOperatDate()));
							}
							//交付日期-计划，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneDueDate())){
								t_msg = "交付日期-计划";
								projectPremisesPmoDto.setPlanneDueDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneDueDate()));
							}
						} catch (Exception e) {
							resDto.setCode("10000006");
							resDto.setDesc("日期转换错误:"+t_msg);
							return resDto;
						}
						//监理单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getSupervUnit())){
							projectPremisesPmoDto.setSupervUnit(reqDto.getProjectDatas().get(i).getData().getSupervUnit());
						}
						//总包单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getContraUnit())){
							projectPremisesPmoDto.setContraUnit(reqDto.getProjectDatas().get(i).getData().getContraUnit());
						}
						//景观单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getSightUnit())){
							projectPremisesPmoDto.setSightUnit(reqDto.getProjectDatas().get(i).getData().getSightUnit());
						}
						//精装修单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDecoraUnit())){
							projectPremisesPmoDto.setDecoraUnit(reqDto.getProjectDatas().get(i).getData().getDecoraUnit());
						}
						//设计单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDesignUnit())){
							projectPremisesPmoDto.setDesignUnit(reqDto.getProjectDatas().get(i).getData().getDesignUnit());
						}
						//建设类型
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getConstrType())){
							projectPremisesPmoDto.setConstrType(reqDto.getProjectDatas().get(i).getData().getConstrType());
						}
						//产权年限，单位：年
						if(StringUtils.isNotEmpty(String.valueOf(reqDto.getProjectDatas().get(i).getData().getProperPeriod()))){
							projectPremisesPmoDto.setProperPeriod(reqDto.getProjectDatas().get(i).getData().getProperPeriod());
						}
						//项目名称【组团不需要存储】
						//规证分期数，单位：期【组团不需要存储】
						//所在城市【组团不需要存储】
						//楼盘地址
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getBuildiAddres())){
							projectPremisesPmoDto.setBuildiAddres(reqDto.getProjectDatas().get(i).getData().getBuildiAddres());
						}
						//项目配套
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProjecSuppor())){
							projectPremisesPmoDto.setProjecSuppor(reqDto.getProjectDatas().get(i).getData().getProjecSuppor());
						}
						//交通情况
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getTraffiStatus())){
							projectPremisesPmoDto.setTraffiStatus(reqDto.getProjectDatas().get(i).getData().getTraffiStatus());
						}
						//开发商名称
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDevelopName())){
							projectPremisesPmoDto.setDevelopName(reqDto.getProjectDatas().get(i).getData().getDevelopName());
						}
						//开发商地址
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDevelopAddres())){
							projectPremisesPmoDto.setDevelopAddres(reqDto.getProjectDatas().get(i).getData().getDevelopAddres());
						}
					
						//物业类型
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProperType())){
							projectPremisesPmoDto.setProperType(reqDto.getProjectDatas().get(i).getData().getProperType());
						}
						//邮政编码
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getZipCode())){
							projectPremisesPmoDto.setZipCode(reqDto.getProjectDatas().get(i).getData().getZipCode());
						}
						//项目LOGO URL，存在多个以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getLogoUrl())){
							projectPremisesPmoDto.setLogoUrl(reqDto.getProjectDatas().get(i).getData().getLogoUrl());
						}
						//总平面图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getMasterDiagra())){
							projectPremisesPmoDto.setMasterDiagra(reqDto.getProjectDatas().get(i).getData().getMasterDiagra());
						}
						//周边配套图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getAroundSupporDiagra())){
							projectPremisesPmoDto.setAroundSupporDiagra(reqDto.getProjectDatas().get(i).getData().getAroundSupporDiagra());
						}
						//交通图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getTraffiDiagra())){
							projectPremisesPmoDto.setTraffiDiagra(reqDto.getProjectDatas().get(i).getData().getTraffiDiagra());
						}
						//实景图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getRealDiagra())){
							projectPremisesPmoDto.setRealDiagra(reqDto.getProjectDatas().get(i).getData().getRealDiagra());
						}
						//样板图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getTemplateDrawing())){
							projectPremisesPmoDto.setTemplateDrawing(reqDto.getProjectDatas().get(i).getData().getTemplateDrawing());
						}
						//效果图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getImpreDrawing())){
							projectPremisesPmoDto.setImpreDrawing(reqDto.getProjectDatas().get(i).getData().getImpreDrawing());
						}
						Long premisesId=null;
						if(projectPremisesPmo != null){
							projectPremisesPmoDto.setId(projectPremisesPmo.getId());
							projectPremisesPmoService.update(projectPremisesPmoDto);
							premisesId=projectPremisesPmo.getPremisesId();
							//四至边界
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getFourBorder())){
								//组团主表
								if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProjectName())){
									ProjectPremisesDto projectPremisesDto = new ProjectPremisesDto();
									projectPremisesDto.setId(projectPremisesPmo.getPremisesId());
									projectPremisesDto.setGroupName(reqDto.getProjectDatas().get(i).getData().getProjectName());
									projectPremisesService.update(projectPremisesDto);
								}
								
								//组团Info信息表
								ProjectPremises projectPremises = projectPremisesService.selectById(projectPremisesPmo.getPremisesId());
								ProjectPremisesInfoDto projectPremisesInfoDto = new ProjectPremisesInfoDto();
								projectPremisesInfoDto.setPremisesId(projectPremises.getId());
								ProjectPremisesInfo projectPremisesInfo = projectPremisesInfoService.selectByDto(projectPremisesInfoDto);
								projectPremisesInfoDto.setFourBorder(reqDto.getProjectDatas().get(i).getData().getFourBorder());
								projectPremisesInfoDto.setId(projectPremisesInfo.getId());
								
								ProjectPremisesInfoDto query=new ProjectPremisesInfoDto();
								query.setPremisesId(projectPremises.getId());
								ProjectPremisesInfo queryPPI=projectPremisesInfoService.selectByDto(query);
								if(null==queryPPI){
									ProjectPremisesInfoDto projectPremisesInfoEntity = new ProjectPremisesInfoDto();
									projectPremisesInfoEntity.setPremisesId(projectPremises.getId());
									projectPremisesInfoEntity.setMerchantId(user.getMerchantId());
									projectPremisesInfoEntity.setUserCode(user.getUserCode());
									projectPremisesInfoEntity.setAccessCode(projectInfo.getProjectCode());
									projectPremisesInfoEntity.setProjectId(projectInfo.getId());
									projectPremisesInfoEntity.setProjectCode(projectInfo.getProjectCode());
									projectPremisesInfoEntity.setFourBorder(reqDto.getProjectDatas().get(i).getData().getFourBorder());
									projectPremisesInfoEntity.setDelFlag(DelFlagEnum.UNDEL.getNo());
									projectPremisesInfoEntity.setCreateUserId(user.getId());
									projectPremisesInfoService.create(projectPremisesInfoEntity);
								}else{
									projectPremisesInfoService.update(projectPremisesInfoDto);
								}
								
							}
						}else{
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProjectName())){
								ProjectPremisesDto projectPremisesDto = new ProjectPremisesDto();
								projectPremisesDto.setMerchantId(projectPmo.getMerchantId());
								projectPremisesDto.setUserCode(user.getUserCode());
								projectPremisesDto.setAccessCode(project.getAccessCode());
								projectPremisesDto.setProjectId(project.getId());
								projectPremisesDto.setProjectCode(project.getProjectCode());
								projectPremisesDto.setGroupName(reqDto.getProjectDatas().get(i).getData().getProjectName());
								projectPremisesDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
								projectPremisesDto.setCreateUserId(user.getId());
								String premisesCode = modelKeyService.next(ModelEnum.PREMISES);
								projectPremisesDto.setPremisesCode(premisesCode);
								ProjectPremisesDto projectPremisesEntity = projectPremisesService.create(projectPremisesDto);
								premisesId=projectPremisesEntity.getId();
								//四至边界
								if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getFourBorder())){
									ProjectPremisesInfoDto projectPremisesInfoEntity = new ProjectPremisesInfoDto();
									projectPremisesInfoEntity.setPremisesId(projectPremisesEntity.getId());
									projectPremisesInfoEntity.setMerchantId(projectPremisesEntity.getMerchantId());
									projectPremisesInfoEntity.setUserCode(projectPremisesEntity.getUserCode());
									projectPremisesInfoEntity.setAccessCode(projectPremisesEntity.getAccessCode());
									projectPremisesInfoEntity.setProjectId(projectPremisesEntity.getId());
									projectPremisesInfoEntity.setProjectCode(projectPremisesEntity.getProjectCode());
									projectPremisesInfoEntity.setFourBorder(reqDto.getProjectDatas().get(i).getData().getFourBorder());
									projectPremisesInfoEntity.setDelFlag(DelFlagEnum.UNDEL.getNo());
									projectPremisesInfoEntity.setCreateUserId(user.getId());
									projectPremisesInfoService.create(projectPremisesInfoEntity);
								}
								
								projectPremisesPmoDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
								projectPremisesPmoDto.setCreateUserId(user.getId());
								projectPremisesPmoDto.setProjectId(project.getId());
								projectPremisesPmoDto.setProjectCode(project.getProjectCode());
								projectPremisesPmoDto.setPremisesId(projectPremisesEntity.getId());
								projectPremisesPmoDto.setPremisesCode(projectPremisesEntity.getPremisesCode());
								projectPremisesPmoDto.setPmoPremisesCode(reqDto.getProjectDatas().get(i).getProjectCode());
								projectPremisesPmoService.create(projectPremisesPmoDto);
							}
						}
						
						if(null!=psList1 && psList1.size()>0 && null!=premisesId){
		                	createOrEditSaleReturn(null,psList1,SaleReturnEnum.SALE, ObjectTypeEnum.PREMISES.getNo(), premisesId);
		                }
		                if(null!=pbList1 && pbList1.size()>0 && null!=premisesId){
		                	createOrEditSaleReturn(pbList1,null,SaleReturnEnum.RETURN,ObjectTypeEnum.PREMISES.getNo(), premisesId);
		                }
					}
				}
			}else{
				/**
				 * 新增项目主表
				 */
				ProjectDto projectDto = new ProjectDto();
				
				//物业类型对应M2产品类型
				String properType=reqDto.getData().getProperType();
				if(StringUtils.isNotEmpty(properType)){
					String[] properTypes=properType.split(",");
					StringBuffer projectTypes=new StringBuffer("");
					for(int i=0;i<properTypes.length;i++){
						ProjectTypeEnum pyEnum=ProjectTypeEnum.getByDescription(properTypes[i]);
						if(null==pyEnum)continue;
						if(StringUtils.isNotBlank(projectTypes.toString())){
							projectTypes.append(",");
						}
						projectTypes.append(pyEnum.getNo());
					}
					projectDto.setProjectType(projectTypes.toString());
					
				}
				//项目名称
				if(StringUtils.isNotEmpty(reqDto.getData().getProjectName())){
					projectDto.setProjectName(reqDto.getData().getProjectName());
				}else{
					resDto.setCode("10000007");
					resDto.setDesc("组团名称为空");
					return resDto;
				}
				//产权年限，单位：年
				if(StringUtils.isNotEmpty(String.valueOf(reqDto.getData().getProperPeriod()))){
					projectDto.setPropertyYear(reqDto.getData().getProperPeriod());
				}
				//规证分期数，单位：期
				if(StringUtils.isNotEmpty(String.valueOf(reqDto.getData().getStageNumber()))){
					projectDto.setStagesNum(reqDto.getData().getStageNumber());
				}
				//所在城市
				CityInfo cityInfo=reqDto.getData().getCity();
				if(null!=cityInfo){
					String province= cityInfo.getProvince();
					String city= cityInfo.getCity();
					String zone= cityInfo.getZone();
					if(StringUtils.isNotBlank(province)){
						AreaDto areaDto = new AreaDto();
						areaDto.setAreaName(province);
						Area area = areaService.selectByDto(areaDto);
						if(null!=area){
							projectDto.setProvinceId(area.getId());
						}
					}
					
					if(StringUtils.isNotBlank(city)){
						AreaDto areaDto = new AreaDto();
						areaDto.setAreaName(city);
						Area area = areaService.selectByDto(areaDto);
						if(null!=area){
							projectDto.setCityId(area.getId());
						}
					}
					
					if(StringUtils.isNotBlank(zone)){
						AreaDto areaDto = new AreaDto();
						areaDto.setAreaName(zone);
						Area area = areaService.selectByDto(areaDto);
						if(null!=area){
							projectDto.setAreaId(area.getId());
						}
					}
					
				}
				//楼盘地址
				if(StringUtils.isNotEmpty(reqDto.getData().getBuildiAddres())){
					projectDto.setPremisesAddress(reqDto.getData().getBuildiAddres());
				}
				//项目配套
				if(StringUtils.isNotEmpty(reqDto.getData().getProjecSuppor())){
					projectDto.setProjectRequirement(reqDto.getData().getProjecSuppor());
				}
				//交通情况
				if(StringUtils.isNotEmpty(reqDto.getData().getTraffiStatus())){
					projectDto.setTrafficCase(reqDto.getData().getTraffiStatus());
				}
				//开发商名称
				if(StringUtils.isNotEmpty(reqDto.getData().getDevelopName())){
					projectDto.setDeveloperName(reqDto.getData().getDevelopName());
				}
				//开发商地址
				if(StringUtils.isNotEmpty(reqDto.getData().getDevelopAddres())){
					projectDto.setDeveloperAddress(reqDto.getData().getDevelopAddres());
				}
				String m1_msg = "";
				try {
					//开工日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneStartOperatDate())){
						m1_msg= "开工日期-计划";
						projectDto.setStartTime(sdf_ymd.parse(reqDto.getData().getPlanneStartOperatDate()));
					}
					//交付日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneDueDate())){
						m1_msg= "交付日期-计划";
						projectDto.setDeliveryDate(sdf_ymd.parse(reqDto.getData().getPlanneDueDate()));
					}
				} catch (Exception e) {
					resDto.setCode("10000006");
					resDto.setDesc("日期转换错误:"+m1_msg);
					return resDto;
				}
				
				projectDto.setMerchantId(user.getMerchantId());
				projectDto.setUserCode(user.getUserCode());
				String projectCode = modelKeyService.next(ModelEnum.PROJECT);
				projectDto.setAccessCode(projectCode);
				projectDto.setProjectCode(projectCode);
				projectDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
				projectDto.setCreateUserId(user.getId());
				ProjectDto pro = projectService.create(projectDto);
				
				/**
				 * 新增项目pmo表
				 */
				//开发周期,格式yyyymmdd-yyyymmdd
				if(StringUtils.isNotEmpty(reqDto.getData().getDevlopCycle())){
					projectPmoDto.setDevlopCycle(reqDto.getData().getDevlopCycle());
				}
				//项目案名
				if(StringUtils.isNotEmpty(reqDto.getData().getProjecCaseName())){
					projectPmoDto.setProjecCaseName(reqDto.getData().getProjecCaseName());
				}
				//计划销售额：单位：万元
				List<PlannedSales> psList=reqDto.getData().getPlanneSalesAmount();
				if(null!=psList && psList.size()>0){
					createOrEditSaleReturn(null,psList,SaleReturnEnum.SALE, ObjectTypeEnum.PROJECT.getNo(),pro.getId());
					String planneSalesAmountJson=JSON.toJSONString(psList);
					//需要实现
					projectPmoDto.setPlanneSalesAmountJson(planneSalesAmountJson);
					
				}
				//计划回款额：单位：万元
				List<PlanneBack> pbList=reqDto.getData().getPlanneBackAmount();
				if(null!=pbList && pbList.size()>0){
					createOrEditSaleReturn(null,psList,SaleReturnEnum.RETURN, ObjectTypeEnum.PROJECT.getNo(),pro.getId());
					//需要实现
					String planneBackAmountJson=JSON.toJSONString(pbList);
					projectPmoDto.setPlanneBackAmountJson(planneBackAmountJson);
				}
				String m2_msg = "";
				try {
					//项目开始日期，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getStartDate())){
						m2_msg = "项目开始日期";
						projectPmoDto.setStartDate(sdf_ymd.parse(reqDto.getData().getStartDate()));
					}
					//项目截止日期，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getEndDate())){
						m2_msg = "项目截止日期";
						projectPmoDto.setEndDate(sdf_ymd.parse(reqDto.getData().getEndDate()));
					}
					//开工日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualStartOperatDate())){
						m2_msg = "开工日期-实际";
						projectPmoDto.setActualStartOperatDate(sdf_ymd.parse(reqDto.getData().getActualStartOperatDate()));
					}
					//交付日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualDueDate())){
						m2_msg = "交付日期-实际";
						projectPmoDto.setActualDueDate(sdf_ymd.parse(reqDto.getData().getActualDueDate()));
					}
					//首开日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneFirstDayStartOperat())){
						m2_msg = "首开日期-计划";
						projectPmoDto.setPlanneFirstDayStartOperat(sdf_ymd.parse(reqDto.getData().getPlanneFirstDayStartOperat()));
					}
					//首开日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualFirstDayStartOperat())){
						m2_msg = "首开日期-实际";
						projectPmoDto.setActualFirstDayStartOperat(sdf_ymd.parse(reqDto.getData().getActualFirstDayStartOperat()));
					}
					//竣工日期-计划，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getPlanneCompleDate())){
						m2_msg = "竣工日期-计划";
						projectPmoDto.setPlanneCompleDate(sdf_ymd.parse(reqDto.getData().getPlanneCompleDate()));
					}
					//竣工日期-实际，格式：yyyymmdd
					if(StringUtils.isNotEmpty(reqDto.getData().getActualCompleDate())){
						m2_msg = "竣工日期-实际";
						projectPmoDto.setActualCompleDate(sdf_ymd.parse(reqDto.getData().getActualCompleDate()));
					}
				} catch (Exception e) {
					resDto.setCode("10000006");
					resDto.setDesc("日期转换错误:"+m2_msg);
					return resDto;
				}
				//监理单位
				if(StringUtils.isNotEmpty(reqDto.getData().getSupervUnit())){
					projectPmoDto.setSupervUnit(reqDto.getData().getSupervUnit());
				}
				//总包单位
				if(StringUtils.isNotEmpty(reqDto.getData().getContraUnit())){
					projectPmoDto.setContraUnit(reqDto.getData().getContraUnit());
				}
				//景观单位
				if(StringUtils.isNotEmpty(reqDto.getData().getSightUnit())){
					projectPmoDto.setSightUnit(reqDto.getData().getSightUnit());
				}
				//精装修单位
				if(StringUtils.isNotEmpty(reqDto.getData().getDecoraUnit())){
					projectPmoDto.setDecoraUnit(reqDto.getData().getDecoraUnit());
				}
				//设计单位
				if(StringUtils.isNotEmpty(reqDto.getData().getDesignUnit())){
					projectPmoDto.setDesignUnit(reqDto.getData().getDesignUnit());
				}
				//建设类型
				if(StringUtils.isNotEmpty(reqDto.getData().getConstrType())){
					projectPmoDto.setConstrType(reqDto.getData().getConstrType());
				}
				if(StringUtils.isNotEmpty(reqDto.getData().getProjectName())){					  
					projectPmoDto.setPmoProjectName(reqDto.getData().getProjectName());
				}
				projectPmoDto.setProjectId(pro.getId());
				projectPmoDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
				projectPmoDto.setMerchantId(pro.getMerchantId());
				projectPmoService.create(projectPmoDto);
				
				/**
				 * 新增项目Info表
				 */
				ProjectInfoDto projectInfoDto = new ProjectInfoDto();
				//物业类型
	/*			if(StringUtils.isNotEmpty(reqDto.getData().getProperType())){
					TenementTypeEnum tenementTypeEnum=TenementTypeEnum.getByDescription(reqDto.getData().getProperType());
					if(null!=tenementTypeEnum){
						projectInfoDto.setTenementType(tenementTypeEnum.getNo());
					}
					
				}*/
				//四至边界
				if(StringUtils.isNotEmpty(reqDto.getData().getFourBorder())){
					projectInfoDto.setFourBorder(reqDto.getData().getFourBorder());
				}
				//邮政编码
				if(StringUtils.isNotEmpty(reqDto.getData().getZipCode())){
					projectInfoDto.setZipCode(reqDto.getData().getZipCode());
				}
				String projectInfoCode = modelKeyService.next(ModelEnum.PROJECT_INFO);
				projectInfoDto.setProjectInfoCode(projectInfoCode);
				projectInfoDto.setProjectId(pro.getId());
				projectInfoDto.setProjectCode(pro.getProjectCode());
				projectInfoDto.setMerchantId(pro.getMerchantId());
				projectInfoDto.setAccessCode(pro.getAccessCode());
				projectInfoDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
				projectInfoDto.setCreateUserId(user.getId());
				projectInfoDto.setUserCode(user.getUserCode());
				projectInfoService.create(projectInfoDto);
				
				/**
				 * 更新项目图片表
				 * 图片入参：存在多个以英文逗号隔开
				 */
				//项目LOGO URL，存在多个以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getLogoUrl())){
					saveProjectImg(user, projectDto, reqDto.getData().getLogoUrl(), "1");
				}
				//总平面图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getMasterDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getMasterDiagra(), "2");
				}
				//周边配套图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getAroundSupporDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getAroundSupporDiagra(), "3");
				}
				//交通图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getTraffiDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getTraffiDiagra(), "4");
				}
				//实景图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getRealDiagra())){
					saveProjectImg(user, projectDto, reqDto.getData().getRealDiagra(), "5");
				}
				//样板图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getTemplateDrawing())){
					saveProjectImg(user, projectDto, reqDto.getData().getTemplateDrawing(), "6");
				}
				//效果图片URL，多个图片以英文逗号隔开
				if(StringUtils.isNotEmpty(reqDto.getData().getImpreDrawing())){
					saveProjectImg(user, projectDto, reqDto.getData().getImpreDrawing(), "7");
				}
				
				/**
				 * 项目组团信息
				 */
				if(null!=reqDto.getProjectDatas() && reqDto.getProjectDatas().size() > 0){
					for(int i=0;i<reqDto.getProjectDatas().size();i++){
						ProjectPremisesPmoDto projectPremisesPmoDto = new ProjectPremisesPmoDto();
						//开发周期、格式为yyyymmdd-yyyymmdd
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDevlopCycle())){
							projectPremisesPmoDto.setDevlopCycle(reqDto.getProjectDatas().get(i).getData().getDevlopCycle());
						}
						//项目案名
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProjecCaseName())){
							projectPremisesPmoDto.setProjectCaseName(reqDto.getProjectDatas().get(i).getData().getProjecCaseName());
						}
						 //计划销售额：单位：万元
		                List<PlannedSales> psList1=reqDto.getData().getPlanneSalesAmount();
		                if(null!=psList1 && psList1.size()>0){
		                	
		                    //需要实现
		                	String planneSalesAmountJson=JSON.toJSONString(psList1);
							//需要实现
		                	projectPremisesPmoDto.setPlanneSalesAmountJson(planneSalesAmountJson);

		                }
		                //计划回款额：单位：万元
		                List<PlanneBack> pbList1=reqDto.getData().getPlanneBackAmount();
		                if(null!=pbList1 && pbList1.size()>0){
		                    //需要实现
							String planneBackAmountJson=JSON.toJSONString(pbList1);
							projectPremisesPmoDto.setPlanneBackAmountJson(planneBackAmountJson);
		                }
		                String m3_msg = "";
						try {
							//项目开始日期，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getStartDate())){
								m3_msg="项目开始日期";
								projectPremisesPmoDto.setStartDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getStartDate()));
							}
							//项目截止日期，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getEndDate())){
								m3_msg="项目截止日期";
								projectPremisesPmoDto.setEndDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getEndDate()));
							}
							//开工日期-实际，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualStartOperatDate())){
								m3_msg="开工日期-实际";
								projectPremisesPmoDto.setActualStartOperatDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualStartOperatDate()));
							}
							//交付日期-实际，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualDueDate())){
								m3_msg="交付日期-实际";
								projectPremisesPmoDto.setActualDueDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualDueDate()));
							}
							//首开日期-计划，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneFirstDayStartOperat())){
								m3_msg="首开日期-计划";
								projectPremisesPmoDto.setPlanneFirstDayStartOperat(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneFirstDayStartOperat()));
							}
							//首开日期-实际，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualFirstDayStartOperat())){
								m3_msg="首开日期-实际";
								projectPremisesPmoDto.setActualFirstDayStartOperat(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualFirstDayStartOperat()));
							}
							//竣工日期-计划，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneCompleDate())){
								m3_msg="竣工日期-计划";
								projectPremisesPmoDto.setPlanneCompleDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneCompleDate()));
							}
							//竣工日期-实际，格式：yyyymmdd
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getActualCompleDate())){
								m3_msg="竣工日期-实际";
								projectPremisesPmoDto.setActualCompleDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getActualCompleDate()));
							}
						} catch (Exception e) {
							resDto.setCode("000011");
							resDto.setDesc("日期转换错误:"+m3_msg);
							return resDto;
						}
						//监理单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getSupervUnit())){
							projectPremisesPmoDto.setSupervUnit(reqDto.getProjectDatas().get(i).getData().getSupervUnit());
						}
						//总包单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getContraUnit())){
							projectPremisesPmoDto.setContraUnit(reqDto.getProjectDatas().get(i).getData().getContraUnit());
						}
						//景观单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getSightUnit())){
							projectPremisesPmoDto.setSightUnit(reqDto.getProjectDatas().get(i).getData().getSightUnit());
						}
						//精装修单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDecoraUnit())){
							projectPremisesPmoDto.setDecoraUnit(reqDto.getProjectDatas().get(i).getData().getDecoraUnit());
						}
						//设计单位
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDesignUnit())){
							projectPremisesPmoDto.setDesignUnit(reqDto.getProjectDatas().get(i).getData().getDesignUnit());
						}
						//建设类型
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getConstrType())){
							projectPremisesPmoDto.setConstrType(reqDto.getProjectDatas().get(i).getData().getConstrType());
						}
						//产权年限，单位：年
						if(StringUtils.isNotEmpty(String.valueOf(reqDto.getProjectDatas().get(i).getData().getProperPeriod()))){
							projectPremisesPmoDto.setProperPeriod(reqDto.getProjectDatas().get(i).getData().getProperPeriod());
						}
						//项目名称【组团不需要存储】
						//规证分期数，单位：期【组团不需要存储】
						//所在城市【组团不需要存储】
						//楼盘地址
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getBuildiAddres())){
							projectPremisesPmoDto.setBuildiAddres(reqDto.getProjectDatas().get(i).getData().getBuildiAddres());
						}
						//项目配套
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProjecSuppor())){
							projectPremisesPmoDto.setProjecSuppor(reqDto.getProjectDatas().get(i).getData().getProjecSuppor());
						}
						//交通情况
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getTraffiStatus())){
							projectPremisesPmoDto.setTraffiStatus(reqDto.getProjectDatas().get(i).getData().getTraffiStatus());
						}
						//开发商名称
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDevelopName())){
							projectPremisesPmoDto.setDevelopName(reqDto.getProjectDatas().get(i).getData().getDevelopName());
						}
						//开发商地址
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getDevelopAddres())){
							projectPremisesPmoDto.setDevelopAddres(reqDto.getProjectDatas().get(i).getData().getDevelopAddres());
						}
						//开工日期-计划，格式：yyyymmdd
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneStartOperatDate())){
							projectPremisesPmoDto.setPlanneStartOperatDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneStartOperatDate()));
						}
						//交付日期-计划，格式：yyyymmdd
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getPlanneDueDate())){
							projectPremisesPmoDto.setPlanneDueDate(sdf_ymd.parse(reqDto.getProjectDatas().get(i).getData().getPlanneDueDate()));
						}
						//物业类型
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProperType())){
							projectPremisesPmoDto.setProperType(reqDto.getProjectDatas().get(i).getData().getProperType());
						}
						//邮政编码
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getZipCode())){
							projectPremisesPmoDto.setZipCode(reqDto.getProjectDatas().get(i).getData().getZipCode());
						}
						//项目LOGO URL，存在多个以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getLogoUrl())){
							projectPremisesPmoDto.setLogoUrl(reqDto.getProjectDatas().get(i).getData().getLogoUrl());
						}
						//总平面图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getMasterDiagra())){
							projectPremisesPmoDto.setMasterDiagra(reqDto.getProjectDatas().get(i).getData().getMasterDiagra());
						}
						//周边配套图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getAroundSupporDiagra())){
							projectPremisesPmoDto.setAroundSupporDiagra(reqDto.getProjectDatas().get(i).getData().getAroundSupporDiagra());
						}
						//交通图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getTraffiDiagra())){
							projectPremisesPmoDto.setTraffiDiagra(reqDto.getProjectDatas().get(i).getData().getTraffiDiagra());
						}
						//实景图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getRealDiagra())){
							projectPremisesPmoDto.setRealDiagra(reqDto.getProjectDatas().get(i).getData().getRealDiagra());
						}
						//样板图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getTemplateDrawing())){
							projectPremisesPmoDto.setTemplateDrawing(reqDto.getProjectDatas().get(i).getData().getTemplateDrawing());
						}
						//效果图片URL，多个图片以英文逗号隔开
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getImpreDrawing())){
							projectPremisesPmoDto.setImpreDrawing(reqDto.getProjectDatas().get(i).getData().getImpreDrawing());
						}
						if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getProjectName())){
							ProjectPremisesDto projectPremisesDto = new ProjectPremisesDto();
							projectPremisesDto.setMerchantId(pro.getMerchantId());
							projectPremisesDto.setUserCode(user.getUserCode());
							projectPremisesDto.setAccessCode(pro.getAccessCode());
							projectPremisesDto.setProjectId(pro.getId());
							projectPremisesDto.setProjectCode(pro.getProjectCode());
							projectPremisesDto.setGroupName(reqDto.getProjectDatas().get(i).getData().getProjectName());
							projectPremisesDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
							projectPremisesDto.setCreateUserId(user.getId());
							String premisesCode = modelKeyService.next(ModelEnum.PREMISES);
							projectPremisesDto.setPremisesCode(premisesCode);
							ProjectPremisesDto projectPremisesEntity = projectPremisesService.create(projectPremisesDto);
							
							//四至边界
							if(StringUtils.isNotEmpty(reqDto.getProjectDatas().get(i).getData().getFourBorder())){
								ProjectPremisesInfoDto projectPremisesInfoEntity = new ProjectPremisesInfoDto();
								projectPremisesInfoEntity.setPremisesId(projectPremisesEntity.getId());
								projectPremisesInfoEntity.setMerchantId(projectPremisesEntity.getMerchantId());
								projectPremisesInfoEntity.setUserCode(projectPremisesEntity.getUserCode());
								projectPremisesInfoEntity.setAccessCode(projectPremisesEntity.getAccessCode());
								projectPremisesInfoEntity.setProjectId(projectPremisesEntity.getId());
								projectPremisesInfoEntity.setProjectCode(projectPremisesEntity.getProjectCode());
								projectPremisesInfoEntity.setFourBorder(reqDto.getProjectDatas().get(i).getData().getFourBorder());
								projectPremisesInfoEntity.setDelFlag(DelFlagEnum.UNDEL.getNo());
								projectPremisesInfoEntity.setCreateUserId(user.getId());
								projectPremisesInfoService.create(projectPremisesInfoEntity);
							}
							
							projectPremisesPmoDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
							projectPremisesPmoDto.setCreateUserId(user.getId());
							projectPremisesPmoDto.setProjectId(pro.getId());
							projectPremisesPmoDto.setProjectCode(pro.getProjectCode());
							projectPremisesPmoDto.setPremisesId(projectPremisesEntity.getId());
							projectPremisesPmoDto.setPremisesCode(projectPremisesEntity.getPremisesCode());
							projectPremisesPmoDto.setPmoPremisesCode(reqDto.getProjectDatas().get(i).getProjectCode());
							projectPremisesPmoService.create(projectPremisesPmoDto);
							 //计划销售额：单位：万元
			           
			                if(null!=psList1 && psList1.size()>0){
			                	createOrEditSaleReturn(null, psList1, SaleReturnEnum.SALE, ObjectTypeEnum.PREMISES.getNo(), projectPremisesEntity.getId());
			                }
			                //计划回款额：单位：万元
			                if(null!=pbList1 && pbList1.size()>0){
			                	createOrEditSaleReturn(pbList1, null, SaleReturnEnum.RETURN, ObjectTypeEnum.PREMISES.getNo(), projectPremisesEntity.getId());
			                }
						}else{
							resDto.setCode("000007");
							resDto.setDesc("组团名称为空");
							return resDto;
						}
					}
				}
			}
			resDto.setCode("000000");
			resDto.setDesc("成功");
		} catch (Exception ex) {
			ex.printStackTrace();
			resDto.setCode("10000008");
			resDto.setDesc(ex.getMessage());
			logger.error("同步项目主数据错误:", ex);
		}finally{
			//记录请求log日志信息
			pmoLogDto.setMerchantId(user==null?1:user.getMerchantId());
			pmoLogDto.setRequestParams(reqDto.getBodyJson());
			pmoLogDto.setDirection("0");
			pmoLogDto.setDelFlag(DelFlagEnum.UNDEL.getNo());
			if(resDto.getCode().equals("000000")){
				pmoLogDto.setStatus("1");
			}else{
				pmoLogDto.setStatus("2");
			}
			pmoLogDto.setReturnResult(JSON.toJSONString(resDto));
			pmoLogDto.setInterfaceName("项目主数据");
			pmoLogService.create(pmoLogDto);
		}
		return resDto;
	}
	
	private void saveProjectImg(User user, ProjectDto projectDto, String proImgUrl, String proType) {
		if (null == projectDto)
			return;
		if (null == proImgUrl)
			return;
		// 删除这个项目下面所有的图片
		if (projectDto.getId() != null) {
			ProjectImgDto dto = new ProjectImgDto();
			dto.setProjectId(projectDto.getId());
			dto.setProjectImgType(proType);
			List<ProjectImg> list = projectImgService.selectListByDto(dto);
			if (list.size() > 0) {
				for (ProjectImg img : list) {
					ProjectImgDto dto_del = new ProjectImgDto();
					dto_del.setId(img.getId());
					projectImgService.destroy(dto_del);
				}
			}
		}
		Long projectId = projectDto.getId();
		String projectCode = projectDto.getProjectCode();
		if("1".equals(proType)){
			// 项目logo
			saveImg(user, projectId, projectCode, proImgUrl, "1");
		}else if("2".equals(proType)){
			// 总平面图
			saveImg(user, projectId, projectCode, proImgUrl, "2");
		}else if("3".equals(proType)){
			// 周边配套图
			saveImg(user, projectId, projectCode, proImgUrl, "3");
		}else if("4".equals(proType)){
			// 交通图
			saveImg(user, projectId, projectCode, proImgUrl, "4");
		}else if("5".equals(proType)){
			// 实景图
			saveImg(user, projectId, projectCode, proImgUrl, "5");
		}else if("6".equals(proType)){
			// 样板图
			saveImg(user, projectId, projectCode, proImgUrl, "6");
		}else if("7".equals(proType)){
			// 效果图
			saveImg(user, projectId, projectCode, proImgUrl, "7");
		}
	}

	private void saveImg(User user, Long projectId, String projectCode,String imgUrl, String type) {
		if (StringUtils.isBlank(imgUrl))
			return;
		String[] urls = imgUrl.split(",");
		if (null == urls || urls.length <= 0)
			return;
		for (int i = 0; i < urls.length; i++) {
			ProjectImgDto projectImgDto = new ProjectImgDto();
			projectImgDto.setUserCode(user.getUserCode());
			projectImgDto.setMerchantId(user.getMerchantId());
			projectImgDto.setDelFlag("0");
			projectImgDto.setAccessCode(projectCode);
			projectImgDto.setLargeUrl(urls[i]);
			projectImgDto.setNormalUrl(urls[i]);
			projectImgDto.setSmallUrl(urls[i]);
			projectImgDto.setProjectImgType(type);
			projectImgDto.setProjectCode(projectCode);
			projectImgDto.setAccessCode(projectCode);
			projectImgDto.setProjectId(projectId);
			projectImgDto.setCreateUserId(user.getId());
			String projectImgCode = modelKeyService.next(ModelEnum.PROJECT_IMG);
			projectImgDto.setProjectImgCode(projectImgCode);
			projectImgService.create(projectImgDto);
		}
	}

}
